ios 11 - UIButton inside UIBarButtonItem causes an autolayout error

前端 未结 3 1818
甜味超标
甜味超标 2021-01-12 05:39

I\'ve a known issue with adding a UIButton into UIBarButtonItem. I\'ve tried to add auto layout constraints as suggested in stackoveflow but I\'m getting an error described

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-12 05:58

    Use this simple way to create button with auto layout. Create button will have with flexible width according to size of the UIView. There is no need to add extra constraints.

    UIButton *sortButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [sortButton setFrame:CGRectMake(10, 0, self.view.frame.size.width - 10, 30)];
    

提交回复
热议问题