Contents

조회 수 4047 댓글 0
Atachment
첨부 '3'
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

iOS 7 이후부터 UINavigationController의 UINavigationBar에 Custom UIBarButtonItem를 사용하면 여백이 생기는 현상이 발생함.


아래 그림처럼..


# iOS 6 일때

ios6.png


# iOS 7 일때는 아래처럼 왼쪽에 여백이 생김

ios7.png


이런 문제를 아래 코드를 이용해 해결할 수 있음.


# UIButton (Alignment)

- (UIEdgeInsets)alignmentRectInsets {
    UIEdgeInsets insets;
    if (SYSTEM_VERSION_LESS_THAN(@"7.0")) {
        if ([self isLeftButton]) {
            insets = UIEdgeInsetsMake(0, 9.0f, 0, 0);
        } else {
            insets = UIEdgeInsetsMake(0, 0, 0, 9.0f);
        }
    } else {
        insets = UIEdgeInsetsZero;
    }

    return insets;
}

- (BOOL)isLeftButton {
    //return self.frame.origin.x) < (self.superview.frame.size.width / 2);
    CGFloat mid = self.frame.origin.x - self.frame.size.width/2;
    return mid < (self.superview.frame.size.width / 2);
}


위의 코드를 수정해서 완성본을 업로드 해두었음..

- 압축 파일 내용

ver1 : 생성자에서 UIButton의 좌우 위치를 지정함 (레거시 코드에 적용시 alloc init 부분 수정 발생)

ver2 : 생성자 없이 UIButton 자신의 좌표로 좌우를 판단해서 알아서 적용 (레거시 코드 바로 적용)


[출처] http://stackoverflow.com/questions/18861201/uibarbuttonitem-with-custom-view-not-properly-aligned-on-ios-7-when-used-as-left


?

  1. [ios] 아이폰에서 진동(Vibrate) 기능 추가하기

    Date2014.04.18 CategoryDevelop Byhooni Views3447
    Read More
  2. [ios] iOS 사운드 관련 프레임워크

    Date2014.04.18 CategoryDevelop Byhooni Views3009
    Read More
  3. [ios] Sprite Kit & 사운드 재생시 백그라운드 진입시 앱이 비정상적으로 종료됨

    Date2014.04.18 CategoryDevelop Byhooni Views3383
    Read More
  4. [ios] DatePicker iOS 6.x 이하 디자인.

    Date2014.04.10 CategoryDevelop Byhooni Views4052
    Read More
  5. [ios] UIWebView 캐쉬 삭제

    Date2014.04.08 CategoryDevelop Byhooni Views3658
    Read More
  6. [ios] UITableView 특정 Row만 Update

    Date2014.04.08 CategoryDevelop Byhooni Views4770
    Read More
  7. [ios] CoreData 사용하기 (튜토리얼)

    Date2014.03.28 CategoryDevelop Byhooni Views3172
    Read More
  8. [ios] SQLite 사용하기(튜토리얼) + 샘플코드

    Date2014.03.28 CategoryDevelop Byhooni Views3693
    Read More
  9. [ios] iOS 7 이상 UIBarButtonItem 여백

    Date2014.03.27 CategoryDevelop Byhooni Views4047
    Read More
  10. [ios] 유용한 매크로

    Date2014.03.26 CategoryDevelop Byhooni Views3652
    Read More
  11. [ios] Using protobuf(Protocol Buffers) on iPhone (iOS)

    Date2014.03.20 CategoryDevelop Byhooni Views4982
    Read More
  12. [ios] Objective-C 프로퍼티의 strong, weak, assign

    Date2014.03.17 CategoryDevelop Byhooni Views4682
    Read More
Board Pagination Prev 1 ... 12 13 14 15 16 17 18 19 20 21 ... 71 Next
/ 71