1

我正在开发一个简单的应用程序,其中包含两个带有按钮的选项卡,按钮在它们之间导航。因为我是 iphone 编程新手,所以无法将按钮对齐到所需的位置。在搜索谷歌时,我得到了一些包含在我的代码中的代码。我附上代码

-(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. 
}

因为我已通过此代码将按钮对齐到右侧,但它位于默认位置。没变。请指导我。提前致谢

4

2 回答 2

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

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

你玩过CGRect吗?

于 2012-09-03T09:03:33.117 回答
0

尝试这个 :

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
于 2012-09-03T07:19:26.463 回答