У меня есть этот код, и я хочу, чтобы моя кнопка как квадрат,, а также под панелью навигации, вы бы Plase помочь мнекак рисовать кнопку площади в прошивкой под навигационной панели
Спасибо заранее!
Я хочу, чтобы моя кнопка в виде квадрата
- (void)viewDidLoad
{
[super viewDidLoad];
int rows = 13, columns = 4;
UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 70*columns, 70*rows)];
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(70 * x, 28 * y, 70, 28);
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonView addSubview: button];
}
}
// Center the view which contains your buttons
CGPoint centerPoint = buttonView.center;
centerPoint.x = self.view.center.x;
buttonView.center = centerPoint;
[self.view addSubview:buttonView];
}
-(void)buttonPressed:(UIButton *)button
{
NSLog(@"button %u -- frame: %@", button.tag, NSStringFromCGRect(button.frame));
}
Edit 2
моя ошибка, когда я с помощью границы
[button.layer setBorderWidth:1.0];
[button.layer setBorderColor:[UIColor blackColor]];
Также не забудьте использовать UIButton * button = [UIButton buttonWithType: UIButtonTypeCustom]; вместо UIButton * button = [UIButton buttonWithType: UIButtonTypeRoundedRect] ;. RoundedRect будет вокруг углов вашей кнопки, в то время как Custom сохранит углы острыми. – Jeremy1026
yeah @ Jeremy1026 верен, если вы используете кнопку по умолчанию, вы получите кнопку с закругленными углами с помощью UIButtonTypeCustom, вы можете делать все, что захотите ... – Ladislav
@ Jeremy1026 благодарит за ответ! когда я использую UIButtonTypeCustom, тогда у меня нет границы, как я могу установить borde? –