iOS UILabel、UIButton文字竖排显示

时间:2023-02-11 10:50:13

- (void)viewDidLoad {

    [superviewDidLoad];

    

    

    

    方法一:


   UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(0,100, 25,200)];

    

    label.text =@"\n\n\n\n\n\n";

    label.numberOfLines = [label.textlength];

    [self.viewaddSubview:label];

    

    方法二:

   UIFont *font = [UIFontsystemFontOfSize:15];

    CGSize sizeWord = [@""sizeWithFont:font constrainedToSize:CGSizeMake(100,1000.0) lineBreakMode:UILineBreakModeWordWrap];

   CGFloat width = sizeWord.width;//一个汉字的宽度

    CGSize sizeStr = [@"是一个小巧的脚本语言。"sizeWithFont:font constrainedToSize:CGSizeMake(width,1000.0) lineBreakMode:UILineBreakModeWordWrap];

   CGFloat hight = sizeStr.height;

    

   UILabel *labelTwo = [[UILabelalloc]initWithFrame:CGRectMake(50,200, width, hight)];

    labelTwo.text =@"是一个小巧的脚本语言。";

    labelTwo.textColor = [UIColorblackColor];

    labelTwo.numberOfLines =0;

    [self.viewaddSubview:labelTwo];

    

    

    

   UIButton *button=[[UIButtonalloc] initWithFrame:CGRectMake(100,400,30, 200)];

    button.titleLabel.font=[UIFontfontWithName:@"Helvetica"size:24];

    [button setTitle:@"其设计目的是为了嵌入应用程序中"forState:UIControlStateNormal];

    [button setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

    [button setTitleColor:[UIColorredColor] forState:UIControlStateHighlighted];

    button.titleLabel.lineBreakMode =UILineBreakModeWordWrap;//换行模式自动换行

    button.titleLabel.numberOfLines =0;

    [self.viewaddSubview:button];

}



   转载请注明出处:http://blog.csdn.net/sevenquan