cocoaPods的使用(自動布局)

pod:查詢cocoaPods的使用方法
pod search XXX
pod init:先要初始化文件贼急,使文件產生Podfile文件
pod install: 更新
重要方法:SnapKit摔刁、PINRemoteImage布卡、SDWebImage拖吼、Kingfisher换淆、SwiftyJSON地技、Alamofire
顏色: ColorPicker
類型轉換: ObjectMapper

let imageView = UIImageView()
        self.view.addSubview(imageView)
        
        imageView.snp.makeConstraints { (make) in
            make.centerX.centerY.equalTo(self.view)
            make.width.height.equalTo(200)
        }
        
        let url = NSURL(string: "http://s1.dwstatic.com/group1/M00/69/44/c0e5bff6974446bb9cd5bec040393a03.gif")
//        imageView.pin_setImageFromURL(url)
        imageView.pin_setImageFromURL(url, placeholderImage: UIImage(named: "cat.jpg"))
//        imageView.startAnimating()
        
        print(NSHomeDirectory())
        
        
//        self.view.translatesAutoresizingMaskIntoConstraints = false
        
        redView = UIView()
        redView.backgroundColor = UIColor.redColor()
        self.view.addSubview(redView)
        
//        redView.snp_makeConstraints { (make) in
//            make.right.equalTo(self.view.snp_right)
//            make.bottom.equalTo(self.view.snp_bottom)
//            make.width.equalTo(100)
//            make.height.equalTo(100)
//        }
        
//        redView.snp.makeConstraints { (make) in
//            make.right.equalTo(self.view.snp.right)
//            make.bottom.equalTo(self.view.snp.bottom)
//            make.size.equalTo(CGSize(width: 100, height: 100))
//        }
        //UIEdgeInsets
        redView.snp.makeConstraints { (make) in
//            make.right.equalTo(self.view)
//            make.bottom.equalTo(self.view)
            make.right.bottom.equalTo(self.view)
//            make.size.equalTo(CGSize(width: 100, height: 100))
            make.width.height.equalTo(self.view).multipliedBy(0.2)

        }
        
//        let width = self.view.frame.size.width
//        let height = self.view.frame.size.height
//        redView.frame = CGRect(x: width - 100, y: height - 100, width: 100, height: 100)
        
        let greenView = UIView()
        greenView.backgroundColor = UIColor.greenColor()
        self.view.addSubview(greenView)
        
        greenView.snp.makeConstraints { (make) in
//            make.top.left.equalTo(redView).offset(20)
            //make.width = redView.width * 0.5
            make.width.height.equalTo(redView).multipliedBy(0.5)
            make.centerX.centerY.equalTo(redView)
        }



//如果一個視圖是通過自動布局設置的位置和大小朗鸠,以后不應該直接修改它的frame,而需要更新(重新設置)約束
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        //更新約束
        redView.snp.updateConstraints { (make) in
//            make.size.equalTo(CGSize(width: 300, height: 300))
            make.size.equalTo(self.view).multipliedBy(0.5)
        }
        
        //重新設置視圖的約束,會將老的約束全部清除
//        redView.snp.remakeConstraints { (make) in
//            make.size.equalTo(CGSize(width: 200, height: 200))
//        }
    }


        //使用SwiftyJSON解析數據
        let json: JSON = JSON(data: data!)
        print(json[0]["title"].string!)
        print(json[0]["price"].float!)
        print(json[2, "price"].float!)
        //轉換成json類型
        let ja = JSON(bookArray!)
        print(ja.rawString()!)

            //1. 下載數據
            //2. 解析數據
            //3. 切換到主線程
            Alamofire.request(.GET, "http://go.class.room/city?areacode=0101").responseJSON { (response) in
            if response.result.error == nil {
                let result = response.result.value
                print(result)
                
                print(NSThread.isMainThread())
            }
        }

tableView的有關使用

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        //只負責重用
        var cell = tableView.dequeueReusableCellWithIdentifier("cell")
        
//        var imageView: UIImageView! //變量必須賦值以后才能使用
        if cell == nil {
            //如果剛創(chuàng)建,肯定是第一次使用
            cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")
            
            let imageView = UIImageView()
            imageView.frame = CGRect(x: 10, y: 10, width: 50, height: 60)
            imageView.tag = 1001 //默認為0
            cell!.contentView.addSubview(imageView)
        }
        
        //1. 作用域 2. 賦值
        let dict = bookArray![indexPath.row]
        let path = dict["cover"] as! String
        
        let imageView = cell!.viewWithTag(1001) as? UIImageView //根據tag值查找子視圖(UIView)
        imageView!.kf_setImageWithURL(NSURL(string: path))

        return cell!
    }



    //切換到主線程
dispatch_async(dispatch_get_main_queue(), { 
                                    self.tableView2.reloadData()
                                })
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末运沦,一起剝皮案震驚了整個濱河市作谚,隨后出現的幾起案子,更是在濱河造成了極大的恐慌段审,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,576評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件闹蒜,死亡現場離奇詭異寺枉,居然都是意外死亡,警方通過查閱死者的電腦和手機绷落,發(fā)現死者居然都...
    沈念sama閱讀 94,515評論 3 399
  • 文/潘曉璐 我一進店門姥闪,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人砌烁,你說我怎么就攤上這事筐喳。” “怎么了往弓?”我有些...
    開封第一講書人閱讀 168,017評論 0 360
  • 文/不壞的土叔 我叫張陵疏唾,是天一觀的道長。 經常有香客問我函似,道長槐脏,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,626評論 1 296
  • 正文 為了忘掉前任撇寞,我火速辦了婚禮顿天,結果婚禮上,老公的妹妹穿的比我還像新娘蔑担。我一直安慰自己牌废,他們只是感情好,可當我...
    茶點故事閱讀 68,625評論 6 397
  • 文/花漫 我一把揭開白布啤握。 她就那樣靜靜地躺著鸟缕,像睡著了一般。 火紅的嫁衣襯著肌膚如雪排抬。 梳的紋絲不亂的頭發(fā)上懂从,一...
    開封第一講書人閱讀 52,255評論 1 308
  • 那天,我揣著相機與錄音蹲蒲,去河邊找鬼番甩。 笑死,一個胖子當著我的面吹牛届搁,可吹牛的內容都是我干的缘薛。 我是一名探鬼主播窍育,決...
    沈念sama閱讀 40,825評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼宴胧!你這毒婦竟也來了漱抓?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,729評論 0 276
  • 序言:老撾萬榮一對情侶失蹤恕齐,失蹤者是張志新(化名)和其女友劉穎辽旋,沒想到半個月后,有當地人在樹林里發(fā)現了一具尸體檐迟,經...
    沈念sama閱讀 46,271評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,363評論 3 340
  • 正文 我和宋清朗相戀三年码耐,在試婚紗的時候發(fā)現自己被綠了追迟。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,498評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡骚腥,死狀恐怖敦间,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情束铭,我是刑警寧澤廓块,帶...
    沈念sama閱讀 36,183評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站契沫,受9級特大地震影響带猴,放射性物質發(fā)生泄漏。R本人自食惡果不足惜懈万,卻給世界環(huán)境...
    茶點故事閱讀 41,867評論 3 333
  • 文/蒙蒙 一拴清、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧会通,春花似錦口予、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,338評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至裳涛,卻和暖如春木张,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背调违。 一陣腳步聲響...
    開封第一講書人閱讀 33,458評論 1 272
  • 我被黑心中介騙來泰國打工窟哺, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人技肩。 一個月前我還...
    沈念sama閱讀 48,906評論 3 376
  • 正文 我出身青樓且轨,卻偏偏與公主長得像浮声,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子旋奢,可洞房花燭夜當晚...
    茶點故事閱讀 45,507評論 2 359

推薦閱讀更多精彩內容