这样: = CGRectMake(x,y,width,height);[btn setTitle: @"search" forState: UIControlStateNormal];//设置按钮上的自体的大小//[btnsetFont:[UIFontsystemFontSize:14.0]]; //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法//应该使用 =[UIFont systemFontOfSize: 14.0];[btnseBackgroundColor:[UIColor blueColor]];//最后将按钮加入到指定视图superView[superView addSubview:btn];扩展资料:注意事项创建按钮的两种方法:1、动态创建btnfont=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];[btnfontsetFrame:CGRectMake(100,10,120,40)];[btnfontaddTarget:selfaction:nilforControlEvents:UIControlEventTouchUpInside];[btnfontsetTitle:@"字体"forState:UIControlStateNormal];=[UIColorclearColor];[:btnfont];2、在xib文件中已经创建好,通过tag获取按钮UIButton*testButton=(UIButton*)[:100];[testButtonaddTarget:selfaction:@selector(test:)forControlEvents:UIControlEventTouchUpInside];
阅读全文 >