如何下划线UIButton的按钮文本? [英] How Can I Underline the Button Text of UIButton?

查看:364
本文介绍了如何下划线UIButton的按钮文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本来自数据库。我想使用它为一个按钮和下划线的按​​钮的文本。

$ p

解决方案

对于这个你可以子类 UILabel 并覆盖其 -drawRect 方法,然后使用您自己的 UILabel 并添加 UIButton <

在UILabel中使用drawRect方法

> - (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetRGBStrokeColor(context,207.0f / 255.0f,91.0f / 255.0f,44.0f / 255.0f,1.0f);

CGContextSetLineWidth(context,1.0f);

CGContextMoveToPoint(context,0,self.bounds.size.height - 1);
CGContextAddLineToPoint(context,self.bounds.size.width,self.bounds.size.height - 1);

CGContextStrokePath(context);

[super drawRect:rect];

}


The text is coming form a database. I would like to use it for a button and underline the text of the button. How can I do that?

解决方案

For this you can subclass UILabel and overwrite its -drawRect method and then use your own UILabel and add a UIButton over it of custom type.

Make your drawRect method in UILabel as

- (void)drawRect:(CGRect)rect 
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBStrokeColor(context, 207.0f/255.0f, 91.0f/255.0f, 44.0f/255.0f, 1.0f);

    CGContextSetLineWidth(context, 1.0f);

    CGContextMoveToPoint(context, 0, self.bounds.size.height - 1);
    CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height - 1);

    CGContextStrokePath(context);

    [super drawRect:rect]; 

}

这篇关于如何下划线UIButton的按钮文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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