IOS UILabel组件

UILabel 是 IOS 显示文字的组件,继承与UIView

属性

名称类型说明默认值
text@property(nullable, nonatomic,copy) NSString文字nil
font@property(null_resettable, nonatomic,strong) UIFont字体大小17
textColor@property(null_resettable, nonatomic,strong) UIColor字体颜色| blackColor
shadowColor@property(nullable, nonatomic,strong) UIColor阴影颜色nil
textAlignment@property(nonatomic) NSTextAlignment字体方向默认为 NSTextAlignmentNatural IOS9之前为 NSTextAlignmentNatural
lineBreakMode@property(nonatomic) NSLineBreakMode换行模式默认为NSLineBreakByTruncatingTail. 可用于多行和单行。
attributedText@property(nullable, nonatomic,copy) NSAttributedString *富文本内容,设置了此属性将不显示text属性。nil
enabled@property(nonatomic,getter=isEnabled) BOOL是否显示YES
numberOfLines@property(nonatomic) NSInteger最多可显示的行数,0表示无限行数1
adjustsFontSizeToFitWidth@property(nonatomic) BOOL是否根据字体大小调整宽度NO
baselineAdjustment@property(nonatomic) UIBaselineAdjustment字体基线UIBaselineAdjustmentAlignBaselines
allowsDefaultTighteningForTruncation@property(nonatomic) BOOL是否允许截断NO

简单代码

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createLableUI];
    [self createSuperLabelUI];
}

// LabelUI
- (void)createLableUI {
    UILabel *label = [[UILabel alloc] init];
    label.text = @"hello wrod";
    // 设置坐标
    label.frame = CGRectMake(100, 100, 200, 50);
    // 设置背景透明颜色 clearColor
    label.backgroundColor = [UIColor clearColor];
    // 设置文字颜色
    label.textColor = [UIColor redColor];
    // 设置字体大小
    label.font = [UIFont systemFontOfSize: 40];
    // 设置阴影
    label.shadowColor = [UIColor redColor];
    // 设置阴影偏移量
    label.shadowOffset = CGSizeMake(2, 2);
    // 设置文字方向
    label.textAlignment = NSTextAlignmentCenter;
    // 设置文字最多行数,默认1行
    label.numberOfLines = 2;
    // 添加视图
    [self.view addSubview:label];
}

- (void)createSuperLabelUI {
    UILabel *superLabel = [[UILabel alloc] init];
    superLabel.frame = CGRectMake(100, 300, 200, 400);
    superLabel.numberOfLines = 0;
    NSString *str = @"Im\nSuper\nLabel";
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
    superLabel.attributedText = text;
    
    [self.view addSubview:superLabel];
}
@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可自定义样式、功能全面的分段控件。项目地址:https://github.com/klongmitre/android-segmented-control-view效果图:如何使用xml中直接创建<org.mitre.ascv.AndroidSegmentedControlView         android:id="@ id/androidSegmentedControlView"         android:layout_width="match_parent"         android:layout_height="wrap_content"         ascv:ascv_defaultSelection="0"         ascv:ascv_unselectedTextColor="@color/test_attr_unselected_text_color"         ascv:ascv_selectedTextColor="@color/test_attr_selected_text_color"         ascv:ascv_selectedColor="@color/test_attr_selected_color"         ascv:ascv_unselectedColor="@color/test_attr_unselected_color"         ascv:ascv_items="@array/three_state_option"/>2. java中添加监听器,监听item的切换ascv = (AndroidSegmentedControlView)this.findViewById(R.id.androidSegmentedControlView); ascv.setIdentifier("ascv01"); //ascv.setItems(new String[]{"Test1aaaaa", "Test2", "Test3"}, new String[]{"1", "2", "3"}); ascv.setOnSelectionChangedListener(new OnSelectionChangedListener(){     @Override     public void newSelection(String identifier, String value) {//当item切换时触发  Toast.makeText(MainActivity.this, "identifier:" identifier "  value:" value, Toast.LENGTH_SHORT).show();     } });参数identifier是当有多个分段控件时,同时使用一个监听器时,用于区别是哪个触发了事件。属性说明属性名类型使用说明ascv_unselectedTextColorreference未选中的item的文字颜色ascv_unselectedColorreference未选中的item的背景颜色,不包括边框ascv_selectedColorreference选中的item背景的颜色以及边框的颜色ascv_selectedTextColorreference选中的item的文字颜色ascv_itemsreference控件item上显示的文字ascv_valuesreference控件item的值,会被传给监听器。未设置时,默认使用ascv_items。ascv_equalWidthboolean当item上的文字,即ascv_items设置的文字,长度不一致时,item的宽度是否还等长。ascv_stretchboolean是否被拉伸。即控件是否填充整个父容器。ascv_defaultSelectioninteger默认哪个item被选中,下标从0开始ascv_identifierstring控件的ID
iOS 中的 UILabel 是一种用于显示文本的控件,它可以用于显示降价信息。你可以使用具有 Markdown 格式的 UILabel,例如使用 YYText 组件。YYText 是 YYKit 的一个组件,它是一个功能强大的 iOS 文本框架,用于显示和编辑富文本。它具有高性能的异步文本布局和渲染,并且扩展了 CoreText 的属性,提供了更多的文本效果。你可以使用 NSMutableAttributedString 来创建富文本字符串,并将其设置给 UILabel 的 attributedText 属性,以实现降价信息的显示。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [CDMarkdownKit:广泛的Swift框架,提供简单且可自定义的markdown解析](https://download.csdn.net/download/weixin_42099087/15035498)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [YYText:用于显示和编辑富文本的 iOS 文本框架-开源](https://download.csdn.net/download/weixin_42116672/20385582)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [GitHub - ElvisCen/PPCounter: 一款简单实用的数字加减动画,支持UILabelUIButton显示](https://blog.csdn.net/weixin_36159799/article/details/117478907)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杨周龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值