第五周個(gè)人預(yù)習(xí)

/// 訪客登錄視圖
class VisitorLoginView: UIView {

override init(frame: CGRect) {
    super.init(frame: frame)

    backgroundColor = UIColor.redColor()
}

required init(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

}


* 修改 `setupVisitorView` 函數(shù)

```swift
// 替換根視圖
view = VisitorLoginView()
  • 添加界面元素
///  設(shè)置 UI 控件
private func setupUI(){
        // 1. 添加控件
        addSubview(iconView)
        addSubview(homeIconView)
        addSubview(messageLabel)
        addSubview(registerButton)
        addSubview(loginButton)
    }

// MARK: - 界面元素懶加載
    /// 背景圖標(biāo)
    private lazy var iconView: UIImageView = {
        let iv = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
        return iv
        }()

    /// 小房子
    private lazy var homeIconView: UIImageView = {
        let iv = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
        return iv
        }()

    /// 消息文字
    private lazy var messageLabel: UILabel = {
        let label = UILabel()
        label.text = "關(guān)注一些人,回這里看看有什么驚喜"
        return label
        }()

    /// 注冊(cè)按鈕
    private lazy var registerButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("注冊(cè)", forState: UIControlState.Normal)
        return btn
        }()

    /// 登錄按鈕
    private lazy var loginButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("登錄", forState: UIControlState.Normal)
        return btn
        }()
  • 設(shè)置自動(dòng)布局
    // 設(shè)置布局
        // 2.1背景圖標(biāo)
        iconView.xmg_AlignInner(type: XMG_AlignType.Center, referView: self, size: nil)

        // 2.3小房子
        homeIconView.xmg_AlignInner(type: XMG_AlignType.Center, referView: self, size: nil)
        // 2.4消息文字
        messageLabel.xmg_AlignVertical(type: XMG_AlignType.BottomCenter, referView: iconView, size: nil)
        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 224))
        // 2.5注冊(cè)按鈕
        registerButton.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: messageLabel, size: CGSize(width: 100, height: 35), offset: CGPoint(x: 0, y: 20))
        // 2.6登錄按鈕
        loginButton.xmg_AlignVertical(type: XMG_AlignType.BottomRight, referView: messageLabel, size: CGSize(width: 100, height: 35), offset: CGPoint(x: 0, y: 20))
  • 懶加載方法補(bǔ)全
    /// 背景圖標(biāo)
    private lazy var iconView: UIImageView = {
        let iv = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
        return iv
        }()

    /// 小房子
    private lazy var homeIconView: UIImageView = {
        let iv = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
        return iv
        }()

    /// 消息文字
    private lazy var messageLabel: UILabel = {
        let label = UILabel()
        label.text = "關(guān)注一些人,回這里看看有什么驚喜"
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(14)
        label.numberOfLines = 0
        label.sizeToFit()
        return label
        }()

    /// 注冊(cè)按鈕
    private lazy var registerButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("注冊(cè)", forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        return btn
        }()

    /// 登錄按鈕
    private lazy var loginButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("登錄", forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        return btn
        }()
  • 按鈕圖片切片

  • 添加遮罩圖片

    /// 遮罩圖片
    // 注意系統(tǒng)有一個(gè)叫做maskView的屬性, 屬性名稱不能叫做maskView
    private lazy var maskIconView: UIImageView = {
        let iv = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))

        return iv
        }()
  • 遮罩圖片自動(dòng)布局
    // 2.2遮罩
    maskIconView.xmg_Fill(self)
  • 視圖背景顏色
backgroundColor = UIColor(white: 237.0 / 255.0, alpha: 1.0)

正則表達(dá)式

在編寫處理字符串的程序時(shí),經(jīng)常會(huì)有查找符合某些復(fù)雜規(guī)則的字符串的需要。正則表達(dá)式就是用于描述這些規(guī)則的工具。換句話說,正則表達(dá)式就是記錄文本規(guī)則的代碼

正則表達(dá)式是對(duì)字符串操作的一種邏輯公式,用事先定義好的一些特定字符、及這些特定字符的組合,組成一個(gè)"規(guī)則字符串",這個(gè)"規(guī)則字符串"用來表達(dá)對(duì)字符串的一種過濾邏輯。

-在很多文本編輯器里,可以使用正則表達(dá)式進(jìn)行檢索,Xcode同樣支持正則表達(dá)式!
-幾乎所有的程序設(shè)計(jì)語言都支持正則表達(dá)式,例如:OC,java,c#,python,js等。
常用正則表達(dá)式:http://www.cnblogs.com/zxin/archive/2013/01/26/2877765.html

NSRegularExpressionCaseInsensitive = 1 << 0, 忽略大小寫
NSRegularExpressionAllowCommentsAndWhitespace = 1 << 1, 忽略空白字符,以及前綴是 # 開始的注釋
NSRegularExpressionIgnoreMetacharacters = 1 << 2, 將整個(gè)匹配方案作為文字字符串
NSRegularExpressionDotMatchesLineSeparators = 1 << 3, 允許 . 匹配任意字符,包括回車換行
NSRegularExpressionAnchorsMatchLines = 1 << 4, 允許 ^ 和 $ 匹配多行文本的開始和結(jié)尾
NSRegularExpressionUseUnixLineSeparators = 1 << 5, 僅將 \n 作為換行符
NSRegularExpressionUseUnicodeWordBoundaries = 1 << 6 使用 Unicode TR#29 指定單詞邊界

url正則:"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"

0> 匹配

(pattern) 匹配pattern并獲取這一匹配,所獲取的匹配可以從產(chǎn)生的Matches集合得到

1> 常用元字符

. 匹配除換行符以外的任意字符
\w 匹配字母或數(shù)字或下劃線或漢字
\s 匹配任意的空白符(空格、TAB\t、回車\r \n)
\d 匹配數(shù)字

^ 匹配字符串的開始
$ 匹配字符串的結(jié)束
\b 匹配單詞的開始或結(jié)束

2> 常用反義符

\W 匹配任意不是字母,數(shù)字,下劃線,漢字的字符
\S 匹配任意不是空白符的字符
\D 匹配任意非數(shù)字的字符

\B 匹配不是單詞開頭或結(jié)束的位置
[^x] 匹配除了x以外的任意字符
[^aeiou] 匹配除了aeiou這幾個(gè)字母以外的任意字符

3> 集合

[xyz] 字符集合
[^xyz] 負(fù)值字符集合
[a-z] 字符范圍
[^a-z] 負(fù)值字符范圍

4> 常用限定符

  •       重復(fù)零次或更多次
    
  •       重復(fù)一次或更多次
    

? 重復(fù)零次或一次
{n} 重復(fù)n次
{n,} 重復(fù)n次或更多次
{n,m} 重復(fù)n到m次

5> 貪婪和懶惰

*? 重復(fù)任意次,但盡可能少重復(fù)
*+ 重復(fù)1次或更多次,但盡可能少重復(fù)
?? 重復(fù)0次或1次,但盡可能少重復(fù)
{n,m}? 重復(fù)n到m次,但盡可能少重復(fù)
{n,}? 重復(fù)n次以上,但盡可能少重復(fù)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容