iOS UILabel、UIButton文字竖排显示

来源:互联网 发布:linux设备驱动功能 编辑:程序博客网 时间:2024/06/01 11:23

 方法一:


    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(010025,200)];

    

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

    label.numberOfLines = [label.text length];

    [self.view addSubview:label];

    

    方法二:

    UIFont *font = [UIFont systemFontOfSize:15];

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

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

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

    CGFloat hight = sizeStr.height;

    

    UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(50200, width, hight)];

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

    labelTwo.textColor = [UIColor blackColor];

    labelTwo.numberOfLines = 0;

    [self.view addSubview:labelTwo];

    

    

    

    UIButton *button=[[UIButton allocinitWithFrame:CGRectMake(100,40030200)];

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

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

    [button setTitleColor:[UIColor blackColorforState:UIControlStateNormal];

    [button setTitleColor:[UIColor redColorforState:UIControlStateHighlighted];

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

    button.titleLabel.numberOfLines = 0;

    [self.view addSubview:button];

0 0
原创粉丝点击