ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Swift] Building Instgram (3)
    공부 기록/Swift 2021. 7. 5. 23:56
    728x90

    https://www.youtube.com/watch?v=3O8U2EecLcg 

     

    CGFloat

    사각형의 위치와 크기(dimension)을 담은 구조. 프레임워크와 관련한 Core graphics 좌표 공간에서 기본적으로 orgin은 사각형의 좌측 아래를 시작으로 우측 위쪽으로 사각형이 extend

    https://developer.apple.com/documentation/coregraphics/cgfloat

     

    Apple Developer Documentation

     

    developer.apple.com

     

    guard (문서 참고, 참고 블로그)

    if문으로 대체할 수 있지만, 가독성을 위해 사용. guard statement가 true이면 지나가고, flase이면 실행하는 구문. 

    출처: https://brunch.co.kr/@robinkangwgmv/4

    headerView에 관한 코드. 이렇게 코드를 작성하면 이렇게 화면이 나타난다.

    y를 safeAreaInset이 아니라 0.0으로 변경하면 화면에 꽉차도록 표시가 된다.

     

    여기에 로고를 추가하는 코드 (로고이미지를 jpg로 하면 투명배경인데도 이렇게 보이므로 png 사용하기. 검색 키워드: "instagram text no background")

     

    safeAreaInsets에 대해서는 https://devmjun.github.io/archive/SafeArea_1참고

    가로, 세로 길이 조정하는 예시.

    그리고 그 밑에 입력필드를 삽입. 

    extension 코드를 추가

    Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you don’t have access to the original source code (known as retroactive modeling). (출처)

    타입에 새로운 기능을 추가할 수 있지만 기존 기능을 오버라이드 할 수 없다.

     

    https://developer.apple.com/documentation/uikit/uicontrol/1618259-addtarget

    https://hyunndyblog.tistory.com/161

    버튼에 대한 event 처리는 1. RxSwift의 subscribe 사용, 2.@objc function 생성 후 addTarget으로 연결하는 방법이 있는데 그 중 2번 방법으로 실행할때 다음 코드를 사용한다.

    @objc

    Swift를 사용한 코드를 Objective-C 코드와 상호작용 시키기 위해 쓰는 키워드

    #selector

    함수를 직접 지정해서 실행할 때 사용되는 함수 선택 지정자(?) 입니다. 본래 Objective-C에서 @selector(methodName)라는 형식으로 사용 되었는데, 런타임에서 선택한 함수가 실행되는 동적 바인딩의 형태 입니다. 이게 Swift로 넘어오면서 #selector() 키워드로 바뀌며 안에 함수를 지정하는 형태가 되었습니다. #selector() 에 전달할 메소드를 작성할 때는 Objective-C와의 호환성을 위해 반드시 함수에 @objc 키워드를 붙여줘야 합니다.

    addTarget(_:action:for:)

    control로 발생하는 이벤트로 target 오브젝트와 action 메서드를 이어주는 함수 입니다

    https://developer.apple.com/documentation/uikit/uiresponder/1621113-becomefirstresponder

     

     

    Apple Developer Documentation

     

    developer.apple.com

    로그인 기능에 대한 코드 분석

    https://developer.apple.com/documentation/uikit/uiresponder/1621097-resignfirstresponder

    resignFirstResponder()

    Notifies this object that it has been asked to relinquish its status as first responder in its window.

    입력을 마쳤거나 다른 이벤트가 호출되었을 때, 키보드 화면을 내리도록 사용.

    참고 블로그: https://loganberry.tistory.com/15

     

    isEmpty

    A Boolean value indicating whether a string has no characters

    string 값이 없는지 알려주는 불리언 값

    '공부 기록 > Swift' 카테고리의 다른 글

    [Swift] Building Instgram (1)(2)  (0) 2021.07.04

    댓글

Designed by Tistory.