閉じるボタンをQuartzCoreだけでつくる
QuartzCore.frameworkをBuildSettingで追加してimport
#import <QuartzCore/QuartzCore.h>
とりあえずalloc
UIButton *XButton = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
背景を黒に
[XButton setBackgroundColor:[UIColor blackColor]];
ボタンの外枠を白で描画
[XButton.layer setBorderWidth:2.0f]; [XButton.layer setBorderColor:[UIColor whiteColor].CGColor];
角を丸くする
[XButton.layer setCornerRadius:21.0f];
X をボタンにセット
[XButton setTitle:@"X" forState:UIControlStateNormal]; [XButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [XButton.titleLabel setFont:[UIFont boldSystemFontOfSize:25.0f]];
addSubviewして終わり
[self.view addSubview:XButton]; [XButton release];
setBackgroundImageを使ってないのでボタンは押されたように反応はしないので注意