在IOS程序中設置UIButton的字體大小


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];

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM