ios - How to set a subview's frame to be its parent's frame in a custom view -


I want to set the frame of the custom view as my SubViews frame, which is UILable but when I self I use the UILabel blank text to see the UILabel to hardcode the parameters in CGRectMake . How to set the frame of UILB to frame the footage?

  - (id) initWithFrame: (CGRect) text with frame: (NSString *) text {self = [super initWithFrame: frame]; If (self) {self.backgroundColor = [UIColor grayColor]; Self. Rounded corner radius = 3; Self.layer.borderWidth = 1; Self.layer.borderColor = [UIColor blackColor] .CGColor; _text = text; } Healthy return; } - (zero) layout subviews {// it works // UILBL * label = [[UILBL Alloc] InitVithframe: CGRactMake (0, 0, 50, 40)]; // This does not work UILabel * label = [[UILabel alloc] initWithFrame: self.frame]; Label.text = @ ""; If (! [Self.text isEqualToString: @ "?"]) {Label.text = self.text; Label.textAlignment = NSTextAlignmentCenter; } [Auto add subeview: label]; }  

layoutsview will be applied multiple times, so that you should not be added. In this way, the better style is to set up the property of UILB, such as your text property:

  @property (nonatomic , Strong) UILabel * label;  

Then change your layout previews :

  - (zero) layouts preview {if (! Self.label) {self. Label = [[UILabel alloc] initWithFrame: self.frame]; // Use ARC self.label.textAlignment = NSTextAlignmentCenter; [Auto add sbewview: self.label]; } Self.label.frame = self.bounds; If (! [Equal Text Equivalent: @ "?"]) {Self.label.text = self.text; }}  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -