簡體   English   中英

UIbutton的對齊

[英]alignment of UIbutton

我正在開發一個包含兩個選項卡的簡單應用程序,其中兩個按鈕帶有導航它們的按鈕。由於我是iPhone編程的新手,因此無法將按鈕對准所需的位置。 在搜索google上,我得到了一些已包含在我的代碼中的代碼。 我正在附上代碼

-(void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(method)forControlEvents:UIControlEventTouchDown];
[button setTitle:@"forward" forState:UIControlStateNormal];
button.frame = CGRectMake(60, 70, 70, 60);
[self.view addSubview:button];
button.titleLabel.textColor = [UIColor redColor];
button.titleLabel.textAlignment = UITextAlignmentRight; //IT IS NOT WORKING
// button.titleLabel.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
//[button setTitle:fromButton.titleLabel.text forState:UI
// Do any additional setup after loading the view, typically from a nib. 
}

因為我已按此代碼將按鈕右對齊,但它處於其默認位置。 沒變。 請指導我。 提前致謝

嘗試這個 :

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
button.frame = CGRectMake(120, 70, 70, 60);

CGRectMake(x,y,寬度,高度)

您玩過CGRect嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM