我正在制作一个我想设置UITextfield
位置的应用程序。但是我陷入其中,它仅设置vertical position
而不是horizontal position
。下面是我的代码和屏幕截图
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 framework
self.Msgtextfield.layer.sublayerTransform=CATransform3DMakeTranslation(5, 0, 0);