IOS Button title居中实现方法实例

来源:互联网 发布:手机淘宝5.9.2旧版本 编辑:程序博客网 时间:2024/05/19 22:25

作者:朱克锋

邮箱:zhukefeng@iboxpay.com

转载请注明出处:http://blog.csdn.net/linux_zkf


这里是先定义一个button,然后在button里添加label视图,错开一定的位置

类似的问题都可以用类似的方法来实现

-(void)drawTitleLabel:(UITableViewCell *)cell withTitle:(NSString *)title withTag:(NSInteger)row

{  

    CLog(@"draw title ...");

    UIButton *btn = nil;

    btn =[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    btn.frame =CGRectMake(MARGIN_LEFT,BTN_MARGIN_HEIGHT, VIEW_WIDTH, BTN_HEIGHT);    

    btn.tag = row;

    [btn setBackgroundImage:[UIImageimageNamed:@"help_btn.png"]forState:UIControlStateNormal];


    [btn addTarget:selfaction:@selector(helpDataButtonPressed:)forControlEvents:UIControlEventTouchUpInside];

    [cell addSubview:btn];

    

    UILabel *ttitleLabel = nil;

    ttitleLabel = [[[UILabelalloc]initWithFrame:CGRectMake(MARGIN_LEFT +4, BTN_MARGIN_HEIGHT,VIEW_WIDTH - 4,BTN_HEIGHT)] autorelease];

    

    [ttitleLabel setBackgroundColor:[UIColorclearColor]];

    [ttitleLabel setFont:[UIFontsystemFontOfSize:FONT_SIZE]];

    ttitleLabel.textColor = [UIColorblackColor];

    ttitleLabel.text = title;

    titleLabel.layer.borderColor = [UIColorclearColor].CGColor;

    [cell addSubview:ttitleLabel];

}


原创粉丝点击