美文网首页关于iOS
自定义按钮(左图片右文字)

自定义按钮(左图片右文字)

作者: 安然slience | 来源:发表于2015-12-17 17:44 被阅读118次

    self.manBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    self.manBtn.frame = CGRectMake(aliasName.frame.origin.x, CGRectGetMaxY(lineview2.frame) + 2, lineview2.frame.size.width/3, aliasName.frame.size.height);

    [self.manBtn setTitle:@"男" forState:UIControlStateNormal];

    [self.manBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    if ([[[NSUserDefaults standardUserDefaults] objectForKey:UserSex] isEqualToString:@"M"]) {

    [self.manBtn setImage:[UIImage imageNamed:@"圈选_2"] forState:UIControlStateNormal];

    }else {

    [self.manBtn setImage:[UIImage imageNamed:@"圈选_1"] forState:UIControlStateNormal];

    }

    [self.manBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 10)];

    [self.manBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, self.manBtn.imageView.bounds.size.width, 0, self.manBtn.imageView.bounds.size.width - 10)];

    [self.manBtn addTarget:self action:@selector(manBtnAction) forControlEvents:UIControlEventTouchUpInside];

    [self.baseScrollView addSubview:self.manBtn];

    具体的间距可以调整以适合自己的界面

    相关文章

      网友评论

        本文标题:自定义按钮(左图片右文字)

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