ios - Positioning UIButtons at top of Screen -



ios - Positioning UIButtons at top of Screen -

what want have 5 buttons as spaced out @ top of screen. tried using constraints buttons squished.

i have code far:

- (void)viewdidload { [super viewdidload]; //i know 2 buttons nsuinteger space = (_backround.frame.size.width - _squareone.frame.size.width * 5) / 6; cgrect newframeone; newframeone = cgrectmake(space, 50, 55, 55); cgrect newframetwo; newframetwo = cgrectmake(space * 2 + _squareone.frame.size.width, 50, 55, 55); _squareone.frame = newframeone; _squaretwo.frame = newframetwo; }

the buttons never show up... , don't know other ways this...

any help?

could seek below?

update: i've written code using xcode time (previously typed memory).

see below screenshot final result.

view controller header file @interface viewcontroller : uiviewcontroller @property (nonatomic, strong) uibutton *btn1; @property (nonatomic, strong) uibutton *btn2; @property (nonatomic, strong) uibutton *btn3; @property (nonatomic, strong) uibutton *btn4; @property (nonatomic, strong) uibutton *btn5; @end view controller implementation file - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. [self initviews]; [self initconstraints]; } -(void)initviews { self.btn1 = [[uibutton alloc] init]; self.btn1.backgroundcolor = [uicolor graycolor]; self.btn2 = [[uibutton alloc] init]; self.btn2.backgroundcolor = [uicolor graycolor]; self.btn3 = [[uibutton alloc] init]; self.btn3.backgroundcolor = [uicolor graycolor]; self.btn4 = [[uibutton alloc] init]; self.btn4.backgroundcolor = [uicolor graycolor]; self.btn5 = [[uibutton alloc] init]; self.btn5.backgroundcolor = [uicolor graycolor]; [self.view addsubview:self.btn1]; [self.view addsubview:self.btn2]; [self.view addsubview:self.btn3]; [self.view addsubview:self.btn4]; [self.view addsubview:self.btn5]; } -(void)initconstraints { self.btn1.translatesautoresizingmaskintoconstraints = no; self.btn2.translatesautoresizingmaskintoconstraints = no; self.btn3.translatesautoresizingmaskintoconstraints = no; self.btn4.translatesautoresizingmaskintoconstraints = no; self.btn5.translatesautoresizingmaskintoconstraints = no; id views = @{ @"btn1": self.btn1, @"btn2": self.btn2, @"btn3": self.btn3, @"btn4": self.btn4, @"btn5": self.btn5 }; // horizontal constraints [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|-5-[btn1]-5-[btn2(==btn1)]-5-[btn3(==btn1)]-5-[btn4(==btn1)]-5-[btn5(==btn1)]-5-|" options:0 metrics:nil views:views]]; // vertical constraints [self.view addconstraint:[nslayoutconstraint constraintwithitem:self.btn1 attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.view attribute:nslayoutattributetop multiplier:1.0 constant:5.0]]; [self.view addconstraint:[nslayoutconstraint constraintwithitem:self.btn2 attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.btn1 attribute:nslayoutattributetop multiplier:1.0 constant:0.0]]; [self.view addconstraint:[nslayoutconstraint constraintwithitem:self.btn3 attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.btn1 attribute:nslayoutattributetop multiplier:1.0 constant:0.0]]; [self.view addconstraint:[nslayoutconstraint constraintwithitem:self.btn4 attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.btn1 attribute:nslayoutattributetop multiplier:1.0 constant:0.0]]; [self.view addconstraint:[nslayoutconstraint constraintwithitem:self.btn5 attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.btn1 attribute:nslayoutattributetop multiplier:1.0 constant:0.0]]; } result

this get.

what long black strip referring to, battery indicator?

ios objective-c uibutton

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -