我想知道如何为UILabel创建文字描边?有没有可能的方法? 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
}
现在的问题是我如何使用这个子类有不同的viewcontrollers一个IBOutlet中的标签。是不是:
label = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, 190, 190)];
你为什么不尝试在Interface Builder中创建'label'并且建立连接以便你的应用程序完成最少的工作? – Lynn 2011-02-23 18:01:46
谢谢:)我很困惑:D现在很好用 – Momi 2011-02-23 20:20:45
谢谢!好想法!仍然需要参数化,如线宽,颜色等。 – Bogdan 2012-07-18 16:23:45