[Swift通天遁地]1、超級工具-(3)帶切換圖標的密碼文本框

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-wjeimmyv-dx.html 
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html

目錄:[Swift]通天遁地Swiftios

本文將演示建立一個帶有標識圖標的密碼文本框。git

首先確保在項目中已經安裝了所需的第三方庫。github

點擊【Podfile】,查看安裝配置文件。swift

1 platform :ios, '12.0'
2 use_frameworks!
3 
4 target 'DemoApp' do
5     source 'https://github.com/CocoaPods/Specs.git'
6     pod 'PasswordTextField'
7 end

根據配置文件中的相關配置,安裝第三方庫。安全

而後點擊打開【DemoApp.xcworkspace】項目文件。微信

像項目中引入一個圖標,該圖標將用做密碼文本框的標識圖標。ide

在項目導航區,打開視圖控制器的代碼文件【ViewController.swift】工具

如今編寫代碼,建立一個帶有標識圖標的密碼文本框。post

 1 import UIKit
 2 //在當前的類文件中,引入已經安裝的第三方類庫。
 3 import PasswordTextField
 4 
 5 class ViewController: UIViewController {
 6 
 7     override func viewDidLoad() {
 8         super.viewDidLoad()
 9         // Do any additional setup after loading the view, typically from a nib.
10         
11         //初始化一個密碼文本輸入框
12         let pwdTextField = PasswordTextField()
13         
14         //設置密碼輸入框的背景顏色爲紫色
15         pwdTextField.backgroundColor = UIColor.purple
16         //設置密碼文本框的顯示區域
17         pwdTextField.frame = CGRect(x: 20, y: 80, width: 280, height: 40)
18         //設置密碼文本框的圓角半徑爲5
19         pwdTextField.layer.cornerRadius = 5
20         //設置密碼文本框的文本顏色爲淺灰色
21         pwdTextField.textColor = UIColor.lightGray
22         //設置密碼文本框的按鈕顯示方式爲始終顯示
23         pwdTextField.showButtonWhile = .Always
24         //設置密碼文本框的圖片前景顏色爲橙色
25         pwdTextField.imageTintColor = .orange
26         
27         //設置密碼文本框的安全文本圖標,在顯示狀態時的圖片。
28         pwdTextField.customShowSecureTextImage = UIImage(named: "password")
29         //設置密碼文本框的安全文本圖標,在隱藏狀態時的圖片
30         pwdTextField.customHideSecureTextImage = UIImage(named: "passwordUnlock")
31         
32         //將密碼文本框,添加到當前視圖控制器的根視圖。
33         self.view.addSubview(pwdTextField)
34     }
35 
36     override func didReceiveMemoryWarning() {
37         super.didReceiveMemoryWarning()
38         // Dispose of any resources that can be recreated.
39     }
40 }
相關文章
相關標籤/搜索