Indent the text in a UITextField

后端 未结 8 1314
日久生厌
日久生厌 2020-12-07 08:35

My question is as simple as the title, but here\'s a little more:

I have a UITextField, on which I\'ve set the background image. The problem is that the text hugs so

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 08:58

    Sometimes the leftView of the textField is a Apple's magnifying glass image. If so, you can set an indent like this:

        UIView *leftView = textField.leftView;
        if (leftView && [leftView isKindOfClass:[UIImageView class]]) {
            leftView.contentMode = UIViewContentModeCenter;
            leftView.width = 20.0f;  //the space you want indented.
        }
    

提交回复
热议问题