美文网首页iOS UI
iOS rightBarButtonItem 设置网络图片,多系

iOS rightBarButtonItem 设置网络图片,多系

作者: 修正 | 来源:发表于2019-07-29 10:03 被阅读0次

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"]];

相关文章

网友评论

    本文标题:iOS rightBarButtonItem 设置网络图片,多系

    本文链接:https://www.haomeiwen.com/subject/qkyvrctx.html