在SWIFT中自定义UITextField

时间:2017-07-19 09:44:19

标签: ios swift swift3

如何在swift 3 IOS中使用UITextField实现以下屏幕。

enter image description here

3 个答案:

答案 0 :(得分:0)

这样做......

  • 为左侧图标图像添加getInfosUser(maxRetries = 2): Observable<Response> { return this.authHttp.get(this.apiUrl+'getuserinfos') .map((response: Response) => { return response; }) .catch((error: any) => { if ( (error.status === 401 || error.status === "401") && maxRetries > 0 ) { return Observable.fromPromise(this.authService.handleError(error)).concat(getInfosUser(maxRetries - 1)); } else { return Observable.throw( new Error(error.status) ); } }) } ,设置所需图像和背景颜色
  • 在imageview旁边添加UIImageView,并在界面构建器(故事板)中将边框样式设置为“无边框样式”
  • 设置所需的背景颜色
  • 也为密码字段执行相同操作,对于眼睛图标视图,请查看此https://github.com/Sahilberi/ImageTextField

答案 1 :(得分:0)

  1. 添加 UITextField

  2. 将子视图添加为 imageView

  3. 设置 UITextField的Alpha

  4. 下面的示例代码:

    private void MasterCheck()
    {
        this.pnlProgress.Visibility = System.Windows.Visibility.Visible;
    
        //I'm using progress bar functionality in ReturnMasters method
        Thread myNewThread = new Thread(() => Auditor.AuditMasterSlides(Globals.ThisAddIn.Application.ActivePresentation, this.pnlMaster, this, token));
    
        token = new CancellationTokenSource();
        myNewThread.Start();
        this.pnlProgress.Visibility = System.Windows.Visibility.Collapsed;
    }
    
    public static void AuditMasterSlides(PPT.Presentation pres, Panel panel, MainProofingTaskPaneControl control, CancellationTokenSource cancToken)
    {
        IDictionary<string,MasterSlide> masterSlides = ReturnMasters(pres, cancToken, control);
        control.ShowAndCollapse(panel);
        control.RemovePanelChildren(panel);
    
        if (masterSlides.Count>1)
        {
            //control.AddControlToPanel(panel, new MasterCheckControlOK());
        }
        else
        {
            control.AddControlToPanel(panel, new MasterCheckControlOK());
        }
    }
    
    internal void RemovePanelChildren(Panel panel)
    {
        this.Dispatcher.Invoke(() =>
        {
            for (int i = panel.Children.Count - 1; i >= 0; i--)
            {
                panel.Children.RemoveAt(i);
            }
        });
    }
    
    internal void AddControlToPanel(Panel panel, Control control)
    {
        MasterCheckControlOK newControl = new MasterCheckControlOK();
    
        this.Dispatcher.Invoke(() =>
        {
            panel.Children.Add(newControl);
        });
    }
    

答案 2 :(得分:0)

导入UIKit

类ViewController:UIViewController {

@IBOutlet weak var txtpassword: UITextField!
@IBOutlet weak var txtUserName: UITextField!
@IBOutlet weak var txtView: UITextView! //your textView


override func viewDidLoad() {

    super.viewDidLoad()
    //navigationBarColor()
    setTextFieldSpace( textField :txtUserName)
    setTextFieldSpace( textField :txtpassword)
    //textField border
    txtpassword.borderStyle = .none
    txtUserName.borderStyle = .none

}

//MARK: - Button Action
// password show hide
@IBAction func btnShowPasswordClick(_ sender: UIButton) {
    if txtpassword.isSecureTextEntry{
        txtpassword.isSecureTextEntry = false
    }else{
        txtpassword.isSecureTextEntry = true
    }
}

//for set space in left side of textField
func setTextFieldSpace( textField :UITextField){
    let lblSpace = UILabel()
    lblSpace.frame = CGRect.init(x: 0, y: 0, width: 5, height: 5)
    lblSpace.backgroundColor = .clear
    textField.leftView = lblSpace

    textField.leftViewMode = .always
    textField.contentVerticalAlignment =  .center
}

}

//查看此Out put

your screen