【发布时间】:2011-07-02 21:05:02
【问题描述】:
我想知道如何为 UILabel 创建文本笔划?有什么可能的方法吗?
谢谢你,
#import <Foundation/Foundation.h>
@interface CustomLabel : UILabel {
}
@end
#import "CustomLabel.h"
@implementation CustomLabel
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 22);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor whiteColor];
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
self.shadowOffset = CGSizeMake(0, 0);
[super drawTextInRect:rect];
self.shadowOffset = shadowOffset;
//works fine with no warning
}
现在的问题是我如何在不同的视图控制器上使用这个带有 IBOutlet 标签的子类。对吗:
label = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, 190, 190)];
【问题讨论】:
-
您为什么不尝试在 Interface Builder 中创建
label并建立连接,以便您的应用完成最少的工作量? -
谢谢 :) 我很困惑 :D 现在效果很好
-
谢谢!好点子!仍然需要参数化,比如线宽、颜色等。