IOS 中UIButton中文字换行

作者: chenhaijian | 来源:发表于2016-05-11 14:49 被阅读3683次
   UIButton *button =[[UIButton alloc]initWithFrame:CGRectMake(100, 100, 200, 40)];
    button.backgroundColor = [UIColor redColor];
    [button setTitle:@"我是Chenhaijian\n   我要换行" forState:UIControlStateNormal];
    button.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
    [self.view addSubview:button];
屏幕快照 2016-05-11 14.59.17.png

相关文章

网友评论

  • 俊一_:没有\n 怎么办
  • Charlie_Brown:写错了,看2楼的写法。
  • GreyWolf:应该是
    [mButton.titleLabel setNumberOfLines:0];
    [mButton.titleLabel setTextAlignment:NSTextAlignmentCenter];

    :smile:

本文标题:IOS 中UIButton中文字换行

本文链接:https://www.haomeiwen.com/subject/bflurttx.html