Simplest way to evenly distribute UIButtons horizontally across width of view controller?

前端 未结 8 896
挽巷
挽巷 2021-02-01 07:48

I\'ve looked through many answers and they all seem very complex! Most recently I was looking at this answer although I\'d prefer not to have to put my buttons inside views.

8条回答
  •  我在风中等你
    2021-02-01 08:10

    You can send the Label/button/view's as array to this methods and arrange the button frames.

    -(void)arrangeViewsXposition:(NSArray*)anyView y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height mainViewWdith:(UIView*)mainview {
    int count = (int)anyView.count;
    CGFloat widthTemp = mainview.bounds.size.width, temp1 = widthTemp-(width*count),space = temp1/(count+1);
    for (int i = 0; i

    Call this method like this:

    [self arrangeViewsXposition:@[btnSave,btnCancel] y:5 width:80 height:30 mainViewWdith:footerView];
    

提交回复
热议问题