Objective c 如何在iPhone应用程序中为文本加下划线
如何在iphoneobjective c中的文本下方划线?UILabel没有简单的下划线。因此有两种方法: 使用UIWebView,您可以使用带下划线的html文本为所需的文本加下划线。 自定义UILabel-对于短的单行标签来说,这是一个好主意。您应该创建一些继承UILabel的CUILabel类,并用以下代码替换@implementation部分中的drawRect方法: `Objective c 如何在iPhone应用程序中为文本加下划线,objective-c,ios4,underline,Objective C,Ios4,Underline,如何在iphoneobjective c中的文本下方划线?UILabel没有简单的下划线。因此有两种方法: 使用UIWebView,您可以使用带下划线的html文本为所需的文本加下划线。 自定义UILabel-对于短的单行标签来说,这是一个好主意。您应该创建一些继承UILabel的CUILabel类,并用以下代码替换@implementation部分中的drawRect方法: ` UILabel没有简单的下划线。因此有两种方法: 使用UIWebView,您可以使用带下划线的html文本为所需的文
UILabel没有简单的下划线。因此有两种方法: 使用UIWebView,您可以使用带下划线的html文本为所需的文本加下划线。 自定义UILabel-对于短的单行标签来说,这是一个好主意。您应该创建一些继承UILabel的CUILabel类,并用以下代码替换@implementation部分中的drawRect方法: `
除了NR4TR的答案之外,另一个选项是使用CoreText。除了NR4TR的答案之外,另一个选项是使用CoreText。我将NR4TR的代码更改为更自动:
#import "UILabelUnderlined.h"
@implementation UILabelUnderlined
@synthesize underlineWidth;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.underlineWidth = 1.0f;
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGFloat red;
CGFloat green;
CGFloat blue;
CGFloat alpha;
[self.textColor getRed:&red green:&green blue:&blue alpha:&alpha];
CGContextSetRGBStrokeColor(ctx, red, green, blue, 1.0f); // Your underline color
CGContextSetLineWidth(ctx, self.underlineWidth);
CGSize constraintSize = CGSizeMake(MAXFLOAT, MAXFLOAT);
CGSize labelSize;
labelSize = [self.text sizeWithFont:self.font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
CGContextMoveToPoint(ctx, 10, self.bounds.size.height - 1);
CGContextAddLineToPoint(ctx, labelSize.width + 10, self.bounds.size.height - 1);
CGContextStrokePath(ctx);
[super drawRect:rect];
}
@end
我将NR4TR的代码更改为更自动:
#import "UILabelUnderlined.h"
@implementation UILabelUnderlined
@synthesize underlineWidth;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.underlineWidth = 1.0f;
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGFloat red;
CGFloat green;
CGFloat blue;
CGFloat alpha;
[self.textColor getRed:&red green:&green blue:&blue alpha:&alpha];
CGContextSetRGBStrokeColor(ctx, red, green, blue, 1.0f); // Your underline color
CGContextSetLineWidth(ctx, self.underlineWidth);
CGSize constraintSize = CGSizeMake(MAXFLOAT, MAXFLOAT);
CGSize labelSize;
labelSize = [self.text sizeWithFont:self.font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
CGContextMoveToPoint(ctx, 10, self.bounds.size.height - 1);
CGContextAddLineToPoint(ctx, labelSize.width + 10, self.bounds.size.height - 1);
CGContextStrokePath(ctx);
[super drawRect:rect];
}
@end
您可以在检测和提供html文本中使用webview和复选标记链接复选框
htmlContentTxt = @"<a title="XYZ" href="http://www.XYZ.com">www.XYZ.com</a>";
[webview loadHTMLString:htmlContentTxt baseURL:nil];
您可以在检测和提供html文本中使用webview和复选标记链接复选框
htmlContentTxt = @"<a title="XYZ" href="http://www.XYZ.com">www.XYZ.com</a>";
[webview loadHTMLString:htmlContentTxt baseURL:nil];
什么文本?在UILabel中?在某个领域?在一个超文本视图中?直接在视图上绘制时?这不是任何人都能回答的问题。什么文本?在UILabel中?在某个领域?在一个超文本视图中?直接在视图上绘制时?这不是任何人都能回答的问题。从文本颜色中丢弃alpha值是故意的吗?从文本颜色中丢弃alpha值是故意的吗?