페이지

2020년 11월 18일 수요일

Setting subViews's constraints in UIScrollView correctly

import SnapKit

 

func setupUI(){


        
view.addSubview(scrollView)

        scrollView.snp.makeConstraints { (mkr) in

            mkr.left.right.top.bottom.equalTo(self.view.safeAreaLayoutGuide)

        }

     

        let view = UIView()

        view.backgroundColor = .yellow

        scrollView.addSubview(view)

        view.snp.makeConstraints{

            $0.left.equalTo(10)

            $0.right.equalTo(10)

            $0.top.equalTo(10)

            $0.height.equalTo(100)

        }


        let view2 = UIView()

        view2.backgroundColor = .green

        scrollView.addSubview(view2)

        view2.snp.makeConstraints{

            $0.width.height.equalTo(200)

            $0.centerX.equalTo(scrollView)

            $0.top.equalTo(10+100+10)

        }

        let view3 = UIView()

        view3.backgroundColor = .orange

        scrollView.addSubview(view3)

        view3.snp.makeConstraints{

            $0.width.height.equalTo(300)

            $0.left.equalTo(10)

            $0.top.equalTo(10+100+10+200+10 )

        }


        scrollView.contentSize = CGSize(width: view.frame.size.width, height:1000)




}


Scrollable content size is ambiguous for UIScrollView

>> instead, Set widthAnchor.



















2020년 10월 8일 목요일

DispatchQueue async, asynAfter

 DispatchQueue.main.async {

            print("async !")

        }




func delay(interval: TimeInterval, closure: @escaping () -> Void) {

         DispatchQueue.main.asyncAfter(deadline: .now() + interval) {

              closure()

         }

    }


2020년 9월 22일 화요일

UITableViewCell insect

 


class NoticeCell: UITableViewCell {

    

    override func layoutSubviews() {

        super.layoutSubviews()

        contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 5, left: 20, bottom: 5, right: 20))


    }


2020년 7월 27일 월요일

usage closure


            let button :UIButton = { ()->UIButton in

                let temp = UIButton()

                return temp

            }()

2020년 3월 11일 수요일

Change navigation back button image



override func viewDidLoad() {
    super.viewDidLoad()
    let backBtn = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    backBtn.setBackButtonBackgroundImage(UIImage(named:"myBackButton"), for: .normal, barMetrics: .default)
    navigationItem.backBarButtonItem = backBtn
    navigationController?.navigationBar.backIndicatorImage = UIImage()
    navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage()

}

2020년 3월 10일 화요일

UINavigationBar Height change


class MyNavigationController : UINavigationController {
    override func viewDidLoad(){
        super.viewDidLoad()
        self.additionalSafeAreaInsets.top = 70 // not including statusBar (44pt), navigationBar (44pt)    
    }
}



2020년 3월 6일 금요일

push vs present



class ViewController:UIViewController {

     ....

     func showPopup(){
            let popupVc = AppDelegate.shared.getVC( "\(PopupViewController.self)")

             // 1. pushViewController
             //self.navigationController?.pushViewController( popupVc,  animated:true)

             // 2. present ViewController

             //self.present( popupVc, animated:true, completion:nil )
     }
}


1. pushViewController

ViewController disappeared. but navigationController manages this ViewController.




2. present ViewController

ViewController didn't disappear.
PopupViewController is stacked on the ViewController.
UIWindow has 2 UITransitionViews ( navigationController , PopupViewController )