UIButton中文字和图片

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(ScreenWidth-135*PIX, 20*PIX, 105*PIX, 88*PIX);
        button.backgroundColor = [UIColor clearColor];
        //设置button正常状态下的图片
        [button setImage:[UIImage imageNamed:@"lajixiang"] forState:UIControlStateNormal];
        //button图片的偏移量,距上左下右分别(10, 10, 10, 60)像素点
        button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 65*PIX);
        [button setTitle:@"清空" forState:UIControlStateNormal];
        //button标题的偏移量,这个偏移量是相对于图片的
//        button.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
        button.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        //设置button正常状态下的标题颜色
        [button setTitleColor:GrayTextColor forState:UIControlStateNormal];
        //设置button高亮状态下的标题颜色
        button.titleLabel.font = [UIFont systemFontOfSize:K_28Size];
        [headerView addSubview:button];
        [button addTarget:self action:@selector(clearAllBtnClicked) forControlEvents:(UIControlEventTouchUpInside)];

你可能感兴趣的:(UIButton中文字和图片)