[英]using an alternative UILabel within a UIButton
this is my first question on this message board so please go easy on me :) 这是我在留言板上的第一个问题,所以请对我轻松一点:)
A while ago I came across a useful piece of code to change a UILabel, this basically surounds the text in the label with a black (or an other color) outline. 不久前,我遇到了一段有用的代码来更改UILabel,这基本上是用黑色(或其他颜色)轮廓包围标签中的文本。
- (void)drawTextInRect:(CGRect)rect; {
CGSize shadowOffset = self.shadowOffset;
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 2);
CGContextSetLineJoin(c, kCGLineJoinRound);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor blackColor];
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
self.shadowOffset = CGSizeMake(0, 0);
[super drawTextInRect:rect];
self.shadowOffset = shadowOffset;
}
I successfully used this as a good template to subclass my UILabels, and now I would say I have a fair understanding on subclassing. 我成功地使用它作为继承UILabels的一个很好的模板,现在我想说我对子类有一个很好的理解。
What I would like to do is use this subclass as the UILabel part of a UIButton so that the text within my buttons have a matching black outline. 我想做的是将此子类用作UIButton的UILabel部分,以便按钮内的文本具有匹配的黑色轮廓。
Any help or even just being pointed in the right direction would be greatly appreciated. 任何帮助,甚至只是指出正确的方向,将不胜感激。
Thanks 谢谢
Dave 戴夫
Why not just subclass UIButton
, and then within that subclass make the same changes you made in your UILabel
subclass to the button's label property. 为什么不只是
UIButton
子类,然后在该子类中对UILabel
子类中的按钮的label属性进行相同的更改。 Basically you would do everything the exact same way, except all of your changes would refer to self.titleLabel
instead of just self
. 基本上,您将以完全相同的方式进行所有操作,除了所有更改都将引用
self.titleLabel
而不是self
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.