开发者

Multiline text in cocoa touch button?

开发者 https://www.devze.com 2023-03-07 04:44 出处:网络
The foll开发者_开发技巧owing code don\'t show up multiline text UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];

The foll开发者_开发技巧owing code don't show up multiline text

UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
viewedYou.frame = CGRectMake(0.0,0.0,61,30);
[viewedYou setTitle:@"Viewed\nYou" forState:UIControlStateNormal];
[self.view addSubview:viewedYou];


do

viewedYou.titleLabel.numberOfLines = 0;
viewedYou.titleLabel.lineBreakMode = UILineBreakModeWordWrap;


Duplicate question: UIButton : Multiline text . But in your case:

    UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
    viewedYou.frame = CGRectMake(0.0,0.0,61,30);

UILabel* viewedYouLabel = [[UILabel alloc] initWithFrame: viewedYou.bounds];
    viewedYouLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
    viewedYouLabel.textAlignment = UITextAlignmentCenter;
    viewedYouLabel.frame = CGRectMake(0.0,0.0,61,30);
    viewedYouLabel.numberOfLines =2;
    viewedYouLabel.text = @"Viewed\nYou";
    [viewedYou addSubview: viewedYouLabel];

    [self.view addSubview:viewedYou];
0

精彩评论

暂无评论...
验证码 换一张
取 消