-
Notifications
You must be signed in to change notification settings - Fork 257
对UILabel添加富文本元素
zhenglibao edited this page Dec 1, 2018
·
2 revisions
<UILabel name="attrLabel" layout="width:100%" attr="linesNum:0,lineSpacing:20">
<Text name="a1" onPress="tapText:" attr="text:这是一个富文本的UILabel控件,font:system|18"/>
<Text onPress="tapText:" attr="text:粗体粗体粗体粗体粗体,font:bold|22"/>
<Text name="a2" onPress="tapText:" attr="text:斜体,font:italic|12,color:red,bgColor:green"/>
<Image name="a3" onPress="tapText:" attr="source:addnewtype.png,size:80/80"/>
<Text onPress="tapText:" attr="text:http://www.baidu.com, font:bold|18,underline:single,color:blue"/>
<Text onPress="tapText:" attr="text:删除线,font:bold|18,strike:single"/>
<Text onPress="tapLabel:" attr="text:请点击这里修改AttributeString,font:bold|18,color:red"/>
</UILabel>
Text和Image支持name, onPress, attr三种属性,不支持layout属性
[attrLabel setFlexAttrString:@"新设置的字符串" name:@"a1"];
[attrLabel updateAttributeText]; //重建attributedText属性
[attrLabel markDirty]; //更新布局
首先onPress后面的selector参数需要包含冒号,当点击事件发生时将会给方法传递FlexClickRange类型的参数,可以据此获取点击信息,然后在响应方法中实现如下:
-(void)tapText:(FlexClickRange*)click
{
NSString* txt = [attrLabel.text substringWithRange:click.range];
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"点击了" message:txt delegate:self cancelButtonTitle:nil otherButtonTitles:@"好的", nil];
[alertview show];
}
具体的例子可以参考demo中的TestScrollView页面
Flexbox Introduction & performance (in Chinese)
Tutorial 1: Create View Controller with xml layout
Tutorial 2: Create Table Cell with xml layout
Tutorial 3: Embed xml layout into traditional view hierarchy
Tutorial 4: Use custom view in xml layout
Tutorial 5: Create reusable view using xml layout file