"一般一个控件元素有下划线并有点击事件的话就应该是一个hyperlinkbutton
1) 用button来实现是最简单的,只需为button设置含下划线的string即可
2) label除了要设置string之外还要加点击事件"
以下是修改字体的代码:
- (void) updateButtonTitle
{
@try {
NSString* titleString = [self title];
NSMutableAttributedString *hyperLinkString = [[NSMutableAttributedString alloc] initWithString: titleString];
NSRange selectedRange = {0, [hyperLinkString length]};
NSDictionary *dict = [[self attributedTitle] attributesAtIndex:0 effectiveRange:&selectedRange];
NSFont *font = [NSFont fontWithName:@"Arial" size:12];
// if(dict && [dict objectForKey:@"NSFont"])
// {
// font = [dict objectForKey:@"NSFont"];
// }
[hyperLinkString beginEditing];
[hyperLinkString addAttribute:NSForegroundColorAttributeName
value:[NSColor colorWithCalibratedRed:0.8086 green:0.8086 blue:0.8086 alpha:1.0] // 更改颜色
range:selectedRange];
[hyperLinkString addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInt:NSSingleUnderlineStyle] // 添加下化线
range:selectedRange];
[hyperLinkString addAttribute:NSFontAttributeName
value:font
range:selectedRange];
[hyperLinkString endEditing];
[self setAttributedTitle: hyperLinkString];
[self sizeToFit];
[hyperLinkString release];
}
@catch (NSException * e) {
}
@finally {
}
}
分享到:
相关推荐
这样的控件通常会监听用户对链接的点击,并触发相应的事件,如打开网页、启动应用内的导航或者其他操作。使用这样的自定义`UILabel`,开发者可以方便地在应用中嵌入网址、电子邮件地址或其他具有特定含义的链接文本...
在标题"(0068)-iOS/iPhone/iPAD/iPod源代码-标签(Label)-Attributed Label"中,我们讨论的是如何利用`NSAttributedString`来实现`UILabel`的功能扩展,特别是在添加下划线、创建文字链接等高级效果方面。...
在事件处理方法中,你可以获取到触发动作的`NSAttributedString`的`link`属性,判断是否是链接并进行相应的操作,如打开Safari浏览器或者启动电话拨号界面。 ```swift let tapGesture = UITapGestureRecognizer...
标题中的"iphone各种型号尺寸.docx"可能是一个文档,包含了关于苹果iPhone各代型号的屏幕尺寸和设计规格。这个标题虽然没有直接关联到“cs”(计算机科学)标签,但我们可以推测讨论的是移动设备的硬件规格,这在...
- 触发器是在特定事件(如插入、更新或删除数据)发生时自动执行的一段SQL代码。 - `INSERTED`表是在插入数据时由系统自动生成的一个临时表,其中包含新插入的数据。 ##### 6.5 第四章节:触发器(DELETED) - `...