我有一個問題,當我嘗試創建一個UIButton有以下選項:標題對齊左,右圖像對齊,UIButton的標題爲對齊左右圖像靠右側
我想這樣做編程,這裏是我tryed,到目前爲止,它的工作原理,但並不像我想
UIButton *definition_title = [UIButton buttonWithType:UIButtonTypeRoundedRect];
definition_title.frame = CGRectMake(0,0, accordion.frame.size.width, 70.0f);
[definition_title setImage:[UIImage imageNamed:@"image_name.png"] forState:UIControlStateNormal];
definition_title.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
definition_title.imageView.contentMode = UIViewContentModeScaleAspectFit;
[definition_title setTitle:@"Scan the Barcode" forState:UIControlStateNormal];
definition_title.titleEdgeInsets = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
definition_title.imageEdgeInsets = UIEdgeInsetsMake(0.0f, accordion.frame.size.width-50, 0.0f, 0.0f);
definition_title.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
上面返回代碼,我的UIButton喜歡這個
________________
| text image|
,但我想它喜歡
________________
|text image|
我認爲那是因爲你的標題標籤居中對齊,加入這行definition_title.titleLabel.textAlignment = NSTextAlignmentLeft; – Hima