我正在制作一个应用程序,我想设置 UITextfield
的位置。但我陷入其中,它只设置垂直位置
而不是水平位置
。下面是我的代码和屏幕截图
Msgtextfield.placeholder=@"demo";
CGRect frame = CGRectMake(100,100,10,100);
UILabel * leftView = [[UILabel alloc] initWithFrame:frame];
leftView.backgroundColor = [UIColor clearColor];
self.Msgtextfield.leftView = leftView;
self.Msgtextfield.leftViewMode = UITextFieldViewModeAlways;
self.Msgtextfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.Msgtextfield.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
最佳答案
使用CATransform3DMakeTranslation
不要忘记导入Quartzcore框架
self.Msgtextfield.layer.sublayerTransform=CATransform3DMakeTranslation(5, 0, 0);
关于ios - UITextfield 的位置未正确设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27182573/