简体   繁体   中英

Cocoa Touch - Custom UILabel

I am trying to create a custom UILabel which sets the background colour to clearColor (with added functionality further down the line). This way, I don't have to specify the exact properties for each label as they will be inherent in every instance of the label.

I have tried several variations on a them but with no success, what am I doing wrong?

@interface ABClearLabel : UILabel {
}
@end

and

@implementation ABClearLabel

- (id)init {
    if (self = [super init]) {
        self.backgroundColor = [UIColor clearColor];
    }
}

Unfortunately, this does not work (I have set the label type in IB as ABClearLabel, as have the instance variables and @property declarations). Please help.

Having played around, IB does it for me - it creates the label with a transparent background. I'm not sure what I had set the previous label to for it not to work. No need for a custom class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM