gpt4 book ai didi

ios4 - 带有轮廓或描边的 uilabel

转载 作者:行者123 更新时间:2023-12-03 18:46:04 39 4
gpt4 key购买 nike

我想知道如何为 UILabel 创建文本描边?有什么可能的办法吗? enter image description here

谢谢,

#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
}

现在的问题是我如何在不同的 View Controller 上使用带有 IBOutlet 标签的子类。对吗:

    label = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, 190, 190)];

最佳答案

根据字体和字符添加它可能会对某些人有所帮助,添加:

CGContextSetLineJoin(c,kCGLineJoinRound);

可以防止因笔划过大而导致字符过于尖锐而产生伪像。

关于ios4 - 带有轮廓或描边的 uilabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5093391/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com