iOS 11 以下的系統(tǒng)只需要設(shè)置frame即可,
iOS 11 以上需設(shè)置布局約束顽冶。
_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需設(shè)置約束,iOS11以下只需要設(shè)置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"]];