【发布时间】:2015-10-19 06:28:47
【问题描述】:
嗨,我是 ios 的初学者,我正在尝试将 UItextfield“文本”数据准确插入 y 轴的中心,如下图文本字段图像所示
我想插入 UIbutton“titleLabel 文本”正好是 x 轴的中心和 y 轴的中心,就像下面的按钮图片一样,我尝试了很多,但没有得到结果,请帮帮我
我的代码:-
[self.TripIdTxt setValue:[UIColor blackColor] forKeyPath:@"_placeholderLabel.textColor"];
self.TripIdTxt.layer.sublayerTransform = CATransform3DMakeTranslation(10.0f, 0.0f, 0.0f);
self.TripIdTxt.backgroundColor = [UIColor whiteColor];
self.TripIdTxt.layer.cornerRadius = 3.0f;
self.TripIdTxt.layer.masksToBounds = YES;
[self.TripIdTxt setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[self.TripIdTxt setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
self.TripIdTxt.textColor = [UIColor blackColor];
self.TripIdTxt.font = [UIFont fontWithName:bitter_Regular size:14];
【问题讨论】:
-
你试过 label.textAlignment = NSTextAlignmentCenter 吗?
-
我只能设置 x 轴的标题标签中心,但我也无法使用您的答案设置 y 轴的中心
-
好的,也许你应该尝试使用 NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style.minimumLineHeight = "你的字体大小" + 5; style.maximumLineHeight = YOUR FONTSIZE" + 5; NSDictionary *attributes = @{NSParagraphStyleAttributeName : style}; yourLabel.setAttributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", attributes:attributes]];跨度>
标签: ios objective-c