小编Ezi*_*met的帖子

目标C Setter覆盖Swift

我需要在我的自定义UIButton子类中覆盖UIViews突出显示属性的setter;

目标C.

@property(nonatomic,getter=isHighlighted) BOOL highlighted; 
Run Code Online (Sandbox Code Playgroud)

像这样被覆盖了

- (void) setHighlighted:(BOOL)highlighted {
    [super setHighlighted:highlighted];

    if (highlighted) {
        self.backgroundColor = UIColorFromRGB(0x387038);
    }
    else {
        self.backgroundColor = UIColorFromRGB(0x5bb75b);
    }

   [super setHighlighted:highlighted];

}
Run Code Online (Sandbox Code Playgroud)

迅速

var highlighted: Bool 
Run Code Online (Sandbox Code Playgroud)

我试过了:

var highlighted: Bool {

   get{ return false }

   set {

        if highlighted {

       self.backgroundColor = UIColor.whiteColor() 
       //Error "Use unresolved identifier     'self'"

         I can't set the background color from value type in here 
        , can't call self.backgroundColor in this value type , 
         can't call super too because this …
Run Code Online (Sandbox Code Playgroud)

uibutton ios swift

35
推荐指数
2
解决办法
2万
查看次数

如何以编程方式创建自定义视图类?

我想创建一个非常简单的customView,上面有一些UIlabel,我该怎么办呢.任何教程或建议将不胜感激.我是新来的,之前没试过.

我用xib试过了.

@interface MyCustomView : UIView

@property (strong, nonatomic) IBOutlet UILabel *Label;

@end
Run Code Online (Sandbox Code Playgroud)

履行

#import "MyCustomTimer.h"
@implementation MyCustomView
-(id)initWithCoder:(NSCoder *)aDecoder{
      if ((self = [super initWithCoder:aDecoder])){
      [self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self     options:nil] objectAtIndex:0]];
       }
     return self;
}
@end
Run Code Online (Sandbox Code Playgroud)

但我需要以编程方式进行,请帮忙.谢谢

iphone custom-view ios ios6

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

ios ×2

custom-view ×1

ios6 ×1

iphone ×1

swift ×1

uibutton ×1