任何一个可以提供一个代码来告诉我怎么强调文本的UILabel?在界面生成器中,我强调了UILabel文本,但它不起作用。
0
A
回答
1
你需要实现你的UIView
继承类的drawRect:
方法。
- (void)drawRect:(CGRect)rect
{
// Get the Render Context
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Measure the font size, so the line fits the text.
// Could be that "titleLabel" is something else in other classes like UILable, dont know.
// So make sure you fix it here if you are enhancing UILabel or something else..
CGSize fontSize =[self.titleLabel.text sizeWithFont:self.titleLabel.font
forWidth:self.bounds.size.width
lineBreakMode:UILineBreakModeTailTruncation];
// Get the fonts color.
const float * colors = CGColorGetComponents(self.titleLabel.textColor.CGColor);
// Sets the color to draw the line
CGContextSetRGBStrokeColor(ctx, colors[0], colors[1], colors[2], 1.0f); // Format : RGBA
// Line Width : make thinner or bigger if you want
CGContextSetLineWidth(ctx, 1.0f);
// Calculate the starting point (left) and target (right)
float fontLeft = self.titleLabel.center.x - fontSize.width/2.0;
float fontRight = self.titleLabel.center.x + fontSize.width/2.0;
// Add Move Command to point the draw cursor to the starting point
CGContextMoveToPoint(ctx, fontLeft, self.bounds.size.height - 1);
// Add Command to draw a Line
CGContextAddLineToPoint(ctx, fontRight, self.bounds.size.height - 1);
// Actually draw the line.
CGContextStrokePath(ctx);
// should be nothing, but who knows...
[super drawRect:rect];
}
采取形式iPhone Programming how to underline UILabel
你也可以继承UILabel
。看到belwo SO帖子,其确实完全相同。
2
可以inheritate的UILabel和自己划清界限在drawTextInRec
相关问题
- 1. 如何强调的UILabel文本 - iPhone应用程序
- 2. 如何在UILabel iPhone SDK中提供选取框效果?
- 3. 如何在iPhone中获取UILabel标签
- 4. 如何在iphone中设置UILabel的值?
- 5. 如何在iPhone SDK
- 6. 如何在iPhone SDK
- 7. 如何在iPhone SDK
- 8. iPhone SDK - 通过UILabel触摸UIButton
- 9. iPhone SDK:断言失败 - [UILabel setFont:]
- 10. iPhone SDK:如何向UILabel的文本添加大纲
- 11. (iPhone SDK)如何将实例变量链接到特定的UILabel
- 12. 如何使一个UILabel闪烁在iPhone
- 13. iPhone:如何在UITableView上添加UILabel?
- 14. 在iphone中排队api调用sdk
- 15. 如何在iphone sdk中滚动tableview时调用服务器?
- 16. 如何在Iphone sdk中调整MpMoviePlayerController的音量?
- 17. 如何在iphone sdk中产生调幅正弦波?
- 18. 如何知道dealloc是否在iphone sdk中被调用?
- 19. 如何在iPhone应用程序中强调文本
- 20. UIView在iphone SDK中,如何更新?
- 21. 如何在iPhone SDK中制作+/-按钮?
- 22. 如何在iPhone SDK中翻转按钮?
- 23. 如何在IB [iPhone SDK]中使用NSLocalizedString?
- 24. 如何在iPhone SDK中裁剪图像?
- 25. 如何在iPhone SDK中使用LinkedIn API?
- 26. 如何在iPhone SDK中使用libtar?
- 27. 如何在Iphone Sdk中使用NSInputStream
- 28. 如何在Xcode5中使用iPhone sdk 6.1?
- 29. 如何在iphone sdk中打开dashcode?
- 30. 如何在iPhone SDK中上传视频