圆形 UI 按钮中的文本未居中对齐 - 目标 C
Text is not center Aligned in Rounded UI Button - ObjectiveC
我使用以下代码制作了一个浮动图标。
- (void)createFloatingButton
{
UIButton *floatingButton = [UIButton buttonWithType:UIButtonTypeCustom];
floatingButton.frame = CGRectMake(kScreenWidth-kFloatingButtonSize-kFloatingButtonSize/2, self.view.frame.size.height-kFloatingButtonSize-kFloatingButtonSize/2, kFloatingButtonSize,kFloatingButtonSize);
[floatingButton setBackgroundColor:kNavColor];
floatingButton.layer.cornerRadius = kFloatingButtonSize/2;
//Configre Font and Text
[floatingButton setTitle:@"+" forState:UIControlStateNormal];
floatingButton.titleLabel.font = [UIFont systemFontOfSize:30];
[floatingButton addTarget:self action:@selector(floatingButtonTapped) forControlEvents:UIControlEventTouchUpInside];
//Mange Alignment
floatingButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
floatingButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//Add shadow
floatingButton.layer.shadowColor = [[UIColor blackColor] CGColor];
floatingButton.layer.shadowOffset = CGSizeMake(0, 2.0f);
floatingButton.layer.shadowOpacity = 0.6f;
floatingButton.layer.shadowRadius = 3.0f;
floatingButton.layer.masksToBounds = NO;
[self.view addSubview:floatingButton];
}
我的输出是这样的:
我不能把 +
放在中间。
我使用以下代码制作了一个浮动图标。
- (void)createFloatingButton
{
UIButton *floatingButton = [UIButton buttonWithType:UIButtonTypeCustom];
floatingButton.frame = CGRectMake(kScreenWidth-kFloatingButtonSize-kFloatingButtonSize/2, self.view.frame.size.height-kFloatingButtonSize-kFloatingButtonSize/2, kFloatingButtonSize,kFloatingButtonSize);
[floatingButton setBackgroundColor:kNavColor];
floatingButton.layer.cornerRadius = kFloatingButtonSize/2;
//Configre Font and Text
[floatingButton setTitle:@"+" forState:UIControlStateNormal];
floatingButton.titleLabel.font = [UIFont systemFontOfSize:30];
[floatingButton addTarget:self action:@selector(floatingButtonTapped) forControlEvents:UIControlEventTouchUpInside];
//Mange Alignment
floatingButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
floatingButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//Add shadow
floatingButton.layer.shadowColor = [[UIColor blackColor] CGColor];
floatingButton.layer.shadowOffset = CGSizeMake(0, 2.0f);
floatingButton.layer.shadowOpacity = 0.6f;
floatingButton.layer.shadowRadius = 3.0f;
floatingButton.layer.masksToBounds = NO;
[self.view addSubview:floatingButton];
}
我的输出是这样的:
我不能把 +
放在中间。