以编程方式创建UILabel [英] create programmatically an UILabel

查看:69
本文介绍了以编程方式创建UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下代码进行了操作:

I did by code the following:

UILabel  * label = [[UILabel alloc] initWithFrame:CGRectMake(40, 70, 300, 50)];
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = UITextAlignmentCenter; // UITextAlignmentCenter, UITextAlignmentLeft
    label.textColor=[UIColor whiteColor];
    label.text = @"Telechargez et consultez les catalogues et les tarifs de la gamme Audi au format PDF";
    [self.view addSubview:label];

它看起来像 但我希望它看起来像.如何更改标签的属性?

And it looks like this but I want it to look like this. How to change the label's properties?

推荐答案

要在图像中显示UILable,您需要设置UILabel ,还可以增加标签的高度.

To show the UILable as your displayed in your image, you need to set the following property of UILabel and also increase the height of your Label.

@property(nonatomic) NSInteger numberOfLines;
@property(nonatomic) UILineBreakMode lineBreakMode;

应如下所示.

    UILabel  * label = [[UILabel alloc] initWithFrame:CGRectMake(40, 70, 300, 100)];
     .................................
    label.numberOfLines=0;
    label.lineBreakMode=UILineBreakModeCharacterWrap;
    ............................

这篇关于以编程方式创建UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆