button标题点击大小变化

来源:互联网 发布:贝叶斯分类算法原理 编辑:程序博客网 时间:2024/06/06 05:19

利用NSMutableAttributedString实现

    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];    button.frame = CGRectMake(100, 100, 100, 30);    button.backgroundColor = [UIColor redColor];    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"压缩图片"];    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:NSMakeRange(0, 2)];    [button setAttributedTitle:str forState:(UIControlStateNormal)];    NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:@"压缩图片"];    [str1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0] range:NSMakeRange(0, 2)];    [button setAttributedTitle:str1 forState:(UIControlStateHighlighted)];    [self.view addSubview:button];
0 0
原创粉丝点击