Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITextfield的位置设置不正确_Ios_Objective C_Uitextfield - Fatal编程技术网

Ios UITextfield的位置设置不正确

Ios UITextfield的位置设置不正确,ios,objective-c,uitextfield,Ios,Objective C,Uitextfield,我正在制作一个应用程序,我想设置我的位置UITextfield。但是我被卡在里面了,它只设置了垂直位置而不是水平位置。下面是我的代码和屏幕截图 Msgtextfield.placeholder=@"demo"; CGRect frame = CGRectMake(100,100,10,100); UILabel * leftView = [[UILabel alloc] initWithFrame:frame]; leftView.backgroundColor = [UIColor clear

我正在制作一个应用程序,我想设置我的位置
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;

创建文本字段的类别类

UITextField+bgImageset.h

@interface UITextField (bgImageset)
-(CGRect)textRectForBounds:(CGRect)bounds;
-(CGRect)editingRectForBounds:(CGRect)bounds;
UITextField+bgImageset.m

@implementation UITextField (bgImageset)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
-(CGRect)textRectForBounds:(CGRect)bounds {

    return CGRectMake(bounds.origin.x+10 , bounds.origin.y ,
                      bounds.size.width - 10 , bounds.size.height );
}
-(CGRect)editingRectForBounds:(CGRect)bounds {
    return [self textRectForBounds:bounds];
}

在要更改光标位置的位置导入此类,并更改文本字段光标的X位置

使用
CATTransferorM3dMakeTransation
不要忘记导入
Quartzcore框架

 self.Msgtextfield.layer.sublayerTransform=CATransform3DMakeTranslation(5, 0, 0);

这一行将起作用。

您想更改
UItextfield
光标
位置
是的。。。我想更改uitextfield光标的位置我使用过但仍然是相同的文本来源将tx-5更改为自定义self@RameshMuthe——坦克斯,我的朋友
UITextField.layer.sublayerTransform=CATransform3DMakeTranslation();