uibutton字体大小

来源:互联网 发布:快速排序的算法 编辑:程序博客网 时间:2024/05/01 06:01

btn.frame = CGRectMake(x, y, width, height);

[btn setTitle@"search" forStateUIControlStateNormal];

//设置按钮上的自体的大小

//[btn setFont: [UIFont systemFontSize: 14.0]];    //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法

//应该使用

btn.titleLabel.font = [UIFont systemFontOfSize14.0];

[btn seBackgroundColor: [UIColor blueColor]];

//最后将按钮加入到指定视图superView

[superView addSubview: btn];


附:创建按钮的两种方法:

1、动态创建
btnfont = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnfont setFrame:CGRectMake(100, 10, 120, 40)];
[btnfont addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[btnfont setTitle:@"字体" forState:UIControlStateNormal];
btnfont.backgroundColor=[UIColor clearColor];
[self.view addSubview:btnfont];
2、在xib文件中已经创建好,通过tag获取按钮
UIButton *testButton= (UIButton*)[self.view viewWithTag:100];
[testButton addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];

注册事件
-(void) test: (id) sender{

UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"ceshi" message:@"test11111" delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease];

[av show];

}

0 0
原创粉丝点击