• 导航栏添加头像 (网络获取图片地址)切圆


    // 导航栏
    - (void) navShowDiffentInfoWith:(NSString *)titleName
    {
        UIBarButtonItem *button3= [[UIBarButtonItem alloc]initWithTitle:titleName style:UIBarButtonItemStyleDone  target:self action:@selector(addFollowAction)];
        NSURL *headerImageUrl = [NSURL URLWithStringAddOffset:self.homePageModelList.creator.headImg];
        UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        UIButton *button = [[UIButton alloc] initWithFrame:contentView.bounds];
        [button addTarget:self action:@selector(imageTapAction) forControlEvents:UIControlEventTouchUpInside];
        if (headerImageUrl) {
            // 网络头像
            [button setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:headerImageUrl]] forState:UIControlStateNormal];
        }else{
            // 本地头像
            [button setImage:[UIImage imageNamed:@"icon_detail_userphoto"] forState:UIControlStateNormal];
        }
        [contentView addSubview:button];
        contentView.layer.cornerRadius = 15;
        contentView.layer.masksToBounds = YES;
        
        UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithCustomView:contentView];
        self.navigationItem.rightBarButtonItems = @[button2,button3];
    }

    注:本地头像如果指定大小可以是圆的,网络图片地址一直会变大变形、这样写加载网络头像不管图片多大 都可以根据自己设置

    contentView大小来调整,有问题可以留言、主页有我的联系方式
  • 相关阅读:
    正则表达式
    匿名函数作业
    内置函数&匿名函数
    模拟面试题一
    迭代器
    生成器
    装饰器
    函数
    疑问?
    3,app信息抽取
  • 原文地址:https://www.cnblogs.com/dujiahong/p/8631405.html
Copyright © 2020-2023  润新知