Level : WORDPRESS BOOK LINKEDIN PATENT Send Mail 동냥하기 hajunho.com

반응형

 var backgroundPanel = UIView()

        

        

        backgroundPanel.backgroundColor = UIColor(red: 33, green: 33, blue: 23, alpha: 1.0)

        

        self.viewArea.addSubview(backgroundPanel)


이런 애들이 반복되면


    lazy var backgroundPanel : [UIView] = {

        let sample = UIView()

        sample.backgroundColor =  colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)

        let ret : [UIView] = Array(repeating: sample, count: 3)

        return ret

    }()


        backgroundPanel[0].snp.makeConstraints {

            $0.width.equalTo(280)

            $0.height.equalTo(44)

            $0.top.equalToSuperview().offset(GS.s.tendency_3dots_popup_lbltxt_topMargin)

            $0.left.equalToSuperview().offset(GS.s.tendency_3dots_popup_label_leftMargin)

        }


       backgroundPanel[1].snp.makeConstraints {

            $0.width.equalTo(350)

            $0.height.equalTo(44)

            $0.top.equalTo(lblLowestCGM.snp.bottom).offset(GS.s.tendency_3dots_popup_lbltxt_topMargin)

            $0.left.equalToSuperview().offset(GS.s.tendency_3dots_popup_label_leftMargin)

        }


        backgroundPanel[2].snp.makeConstraints {

            $0.width.equalTo(300)

            $0.height.equalTo(44)

            $0.top.equalTo(lblAvgSG.snp.bottom).offset(GS.s.tendency_3dots_popup_lbltxt_topMargin)

            $0.left.equalToSuperview().offset(GS.s.tendency_3dots_popup_label_leftMargin)

        }



이렇게 만들어 보고 싶을 것이다. 그러나 sample 은 하나의 객체이므로 

        var sample1 = UIView()

        sample1.backgroundColor =  colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)

        var sample2 = UIView()

        sample2.backgroundColor =  colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)

        var sample3 = UIView()

        sample3.backgroundColor =  colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)

        let ret : [UIView] = [sample1, sample2, sample3]


와 같이 다른 객체로 넘겨 주어야 한다. 코드를 줄이면, 


        let ret : [UIView] = [UIView(), UIView(), UIView()]

        for men in ret {

            men.backgroundColor =  colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)

        }

겠지.






반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기