iOS 11 以下的系统只需要设置frame即可,
iOS 11 以上需设置布局约束。
_profileBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_profileBtn.frame = CGRectMake(0, 0, 27, 27);
_profileBtn.layer.cornerRadius = 13.5;
_profileBtn.layer.masksToBounds = YES;
[_profileBtn addTarget:self action:@selector(handleProfileClicked:) forControlEvents:UIControlEventTouchUpInside];
// ------- iOS >= 11需设置约束,iOS11以下只需要设置frame即可
if (@available(iOS 11, *)) {
[_profileBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@27);
}];
}
// ------
UIBarButtonItem *profileItem = [[UIBarButtonItem alloc] initWithCustomView:self.profileBtn];
self.navigationItem.rightBarButtonItem = profileItem;
[self.profileBtn sd_setImageWithURL:[NSURL URLWithString:[user getLogoImg]]
forState:UIControlStateNormal
placeholderImage:[UIImage imageNamed:@"default_avatar"]];
网友评论