ios字体设置

来源:互联网 发布:evdo.evdo_a是什么网络 编辑:程序博客网 时间:2024/05/22 09:17
在IOS程序中设置UIButton的字体大小
  1. btn.frame = CGRectMake(x, y, width, height); 

  2. [btn setTitle: @"search" forState: UIControlStateNormal]; 

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

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

  5. //应该使用 

  6. btn.titleLabel.font = [UIFont systemFontOfSize: 14.0]; 

  7. [btn seBackgroundColor: [UIColor blueColor]]; 

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

  9. [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
原创粉丝点击