๊ธ€ ์ž‘์„ฑ์ž: ์ด์ง€์›๐ŸŒฉ๏ธ

Storyboard Reference

์„ธ ๋ช…์ด์„œ ์ž‘์—…์„ ํ–ˆ๊ณ , ์ฒ˜์Œ์—๋Š” ์Šคํ† ๋ฆฌ๋ณด๋“œ๋ฅผ ์•ˆ ์“ฐ๊ณ  ์ „๋ถ€ ์ฝ”๋“œ๋กœ ์ž‘์„ฑํ•˜๊ธฐ๋กœ ํ–ˆ๋Š”๋ฐ, ์ค‘๊ฐ„์— ์Šคํ† ๋ฆฌ๋ณด๋“œ๋„ ์“ฐ๊ฒŒ ๋˜์—ˆ๋‹ค. ์“ธ ์‚ฌ๋žŒ์€ ์“ฐ๊ณ , ์•ˆ ์“ธ ์‚ฌ๋žŒ์€ ์•ˆ ์“ฐ๋Š” ์ƒํ™ฉ์ด ๋˜์—ˆ๋‹ค. ์„œ๋กœ์˜ ์Šคํ† ๋ฆฌ๋ณด๋“œ๋ฅผ ๊ฑด๋“œ๋ฆฌ์ง€ ์•Š๊ธฐ ์œ„ํ•ด์„œ ์–ด๋–ค ์‹์œผ๋กœ ๋‚˜๋ˆ„์—ˆ๋ƒ๋ฉด,

1. ๊ธฐ๋Šฅ๋ณ„ ๊ทธ๋ฃน์„ ๋งŒ๋“ ๋‹ค.

2. ๊ฐ ๊ธฐ๋Šฅ๋ณ„ ์Šคํ† ๋ฆฌ๋ณด๋“œ๋ฅผ ๋งŒ๋“ ๋‹ค.

3. ๊ธฐ๋Šฅ๋ณ„ ์Šคํ† ๋ฆฌ๋ณด๋“œ๋ฅผ main.storyboard์—์„œ Storyboard Reference๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์—ฐ๊ฒฐํ•œ๋‹ค.

+ ํƒญ ๋ฐ”์™€ ๋„ค๋น„๊ฒŒ์ด์…˜ ์ปจํŠธ๋กค๋Ÿฌ ๋‘˜ ๋‹ค ์‚ฌ์šฉํ–ˆ์Œ

main.storyboard์— ํ•œ ๋ฒˆ ๋ชจ๋“  ๊ธฐ๋Šฅ์˜ ํ๋ฆ„์„ ์—ฐ๊ฒฐํ•ด๋†“์œผ๋‹ˆ๊นŒ ๋ณด๊ธฐ์—๋„ ์ข‹๊ณ , ์Šคํ† ๋ฆฌ๋ณด๋“œ ์ถฉ๋Œ ๋‚  ์ผ๋„ ์—†์–ด์„œ ์ข‹์•˜๋‹ค. 

 

์ฝ”๋“œ๋กœ ์Šคํฌ๋กค๋ทฐ ๋งŒ๋“ค๊ธฐ

๊ฐ™์ด ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•œ ํƒํ˜„๋‹˜์ด ์•Œ๋ ค์ฃผ์‹  ์œ ํŠœ๋ธŒ ๋™์˜์ƒ์ด ์—„์ฒญ ๋„์›€์ด ๋งŽ์ด ๋˜์—ˆ๋‹ค.

class ViewController: UIViewController {
    // MARK:- Properties
    lazy var contentViewSize = CGSize(width: self.view.frame.width, height: self.view.frame.height)    

    // MARK:- Views
    lazy var scrollView: UIScrollView = {
        let view = UIScrollView(frame: .zero)
        view.bacgkroundColor = .white
        view.frame = self.view.bounds
        view.contentSize = contentViewSize
        return view
    }()

    lazy var containerView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.frame.size = contentViewSize
        return view
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white
        view.addSubview(scrollView)
        scrollView.addSubview(containerView)
        // containerView.addSubView(component)
    }
}

 

์Šคํ† ๋ฆฌ๋ณด๋“œ์—์„œ ์ƒ์„ฑํ•œ Navigation Controller ์ œ์•ฝ์กฐ๊ฑด ์ฃผ๋Š” ๋ฐฉ๋ฒ•

  1. ์Šคํ† ๋ฆฌ๋ณด๋“œ์—์„œ Navigation Controller๋ฅผ ๋งŒ๋“ ๋‹ค.
  2. ๋‚˜๋จธ์ง€ View๋Š” ์ฝ”๋“œ๋กœ ์ž‘์„ฑํ•œ๋‹ค.

์ด๋Ÿฌํ•œ ์ƒํ™ฉ์—์„œ ์–ด๋–ค view component๋ฅผ ๋„ค๋น„๊ฒŒ์ด์…˜ ์ปจํŠธ๋กค๋Ÿฌ๋กœ๋ถ€ํ„ฐ 8๋งŒํผ ๋–จ์–ด์ง€๊ฒŒ ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋ฉด ๋œ๋‹ค. (SnapKit ์‚ฌ์šฉ)

view.snp.makeConstraint {
    $0.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(8)
 

jwonyLee/TIL

Today I Learned. Contribute to jwonyLee/TIL development by creating an account on GitHub.

github.com

 

ํ…Œ์ด๋ธ”๋ทฐ ์…€ ์‚ฌ์ด์˜ ์„  ์ง€์šฐ๊ธฐ

์ฝ”๋“œ๋กœ ์ž‘์„ฑ๋œ ํ…Œ์ด๋ธ”๋ทฐ ์…€ ์‚ฌ์ด์˜ ์„ ์„ ์ง€์šฐ๊ณ  ์‹ถ๋‹ค๋ฉด, tableView.separatorStyle = .none์„ ์“ฐ๋ฉด ๋œ๋‹ค. ์ด๋•Œ ์ฃผ์˜ํ•ด์•ผ ํ•  ์ ์€, ์ดˆ๊ธฐ ์ƒ์„ฑ ์‹œ์— ์ž‘์„ฑํ•˜๋ฉด ์•ˆ ๋œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

๐Ÿšซ Bad

let tableView = UITableView().then {
    $0.separatorStyle = .none
}

๐Ÿ‘ Correct

let tableView = UITableView().then {
    // set tableView
}

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.separatorStyle = .none
}
 

jwonyLee/TIL

Today I Learned. Contribute to jwonyLee/TIL development by creating an account on GitHub.

github.com

 

๋ฐ˜์‘ํ˜•