0
UILabel을 하위 클래스로 만들려고합니다.UILabel Subclass Text가 사라짐
코드 .H
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface PercentLabel : UILabel
@property (nonatomic) IBInspectable CGFloat ratio;
@property (nonatomic) IBInspectable UIColor *color1;
@property (nonatomic) IBInspectable UIColor *color2;
- (void)drawRect:(CGRect)rect;
@end
코드하는 .m
#import "PercentLabel.h"
@implementation PercentLabel
- (void)drawRect:(CGRect)rect {
// Drawing code
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [_color1 CGColor]);
CGContextFillRect(context, rect);
}
@end
사용자 지정 속성이 스토리 보드에서 잘 작동하지만, Rectfill 내가 가진 텍스트를 포함 보인다. 예를 들어 불투명도 0.5로 색상을 설정하면 색상 뒤에 텍스트가 표시됩니다.
누군가가 이것이 왜 그렇게하고 텍스트를 맨 위에 표시하도록 수정해야하는지 설명 할 수 있습니까?
이미 해결책을 찾았습니다. 그냥 [super drawRect : rect]를 넣어야합니다. 그리기 후. Lulzz 멍청한 녀석들이 사람들을 부르짖어. – GeneCode