嗨,我是ios的初学者,我正在尝试插入UItextfield" text"准确地位于y轴中心的数据,如下面的文本域图像
我想插入UI按钮" titleLabel text"正好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];
答案 0 :(得分:2)
设置
代表UIButton
yourbtnName.titleLabel.textAlignment = NSTextAlignmentCenter;
表示y轴
[yourbtnName setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
表示X轴
[yourbtnName setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
代表UITextFields
yourtextfieldName.textAlignment = NSTextAlignmentCenter;
你可以在故事板中访问
有关其他信息,请参阅此link
使用TextField填充
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
TripIdTxt.leftView = paddingView;
self. TripIdTxt.leftViewMode = UITextFieldViewModeAlways;
或者使用Transform
TripIdTxt.layer.sublayerTransform = CATransform3DMakeTranslation(10.0f, 0.0f, 0.0f);
答案 1 :(得分:0)
设置标签属性的文本对齐中心。
mainlabel.textAlignment = NSTextAlignmentCenter;
答案 2 :(得分:0)