iOS 개발에서 자주 사용하는 처리 및 기술

3009 단어

디버그할 때 대상의 구체적인 데이터를 출력합니다


모델 클래스에서 debugDescription 메서드 다시 쓰기
debugDescription은 인터럽트가 LLDB po 명령을 통해 대상을 인쇄할 때 호출됩니다. 이 방법은 NSObject 프로토콜의 한 방법입니다. NSObject에서는 기본적으로 실행되었고, 기본값은 인쇄 대상의 주소와 클래스입니다.
모델에서 이 방법을 다시 쓰고 출력 내용을 사용자 정의합니다

- (NSString *)debugDescription {

return [NSString stringWithFormat:@":%@",[self class],&self,@{@"name" : _name,@"age" : _age}];

}


내비게이션 표시줄 투명성


내비게이션 표시줄에 빈 배경 그림 한 장을 주면 된다

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];


탐색 모음의 선도 투명하게 만들기

self.navigationController.navigationBar.shadowImage = [UIImage new];


드롭다운 거리에 따라 내비게이션 막대 투명도 조정

[[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 0; //  alpha 


탐색 모음 배경색 설정


self.navigationBar.barTintColor = [UIColor orangeColor];


전역적으로 navigationBar, Tabbar 스타일 설정


[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];

[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}];

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:10]}];


뷰의 모든 하위 뷰 인쇄하기


po [[self view] recursiveDescription]


로드 xib에서 UIView로 변환

  • UINib 로드
  • 
    UINib *nib = [UINib nibWithNibName:@"XLStockOrdersSectionHeader" bundle:[NSBundle mainBundle]];
    
    UIView *header = (UIView *)[nib instantiateWithOwner:nil options:nil].firstObject;
    
    
  • NSBundle 로딩
  • 
    UIView *header = (UIView *)[[NSBundle mainBundle] loadNibNamed:@"XLStockOrdersSectionHeader" owner:nil options:nil].firstObject;
    
    

    UINib 및 NSBundle
    NSBundle 로드는 항상 로컬에서 xib를 메모리로 읽기
    UINib 는 xib 를 로드한 후 메모리에 캐시되며, 다시 xib 를 변경해야 할 때 메모리에서 읽습니다

    presentViewController

    
    TestViewController *testVC = [[TestViewController alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:testVC];
    
    [self presentViewController:nav animated:YES completion:nil];
    
    

    모든 컨트롤러에 아래의 방법을 추가하여 모든 컨트롤러의 소각을 편리하게 감시해야 한다

    
    - (void)dealloc {
    
    #ifdef DEBUG
    
    NSLog(@"dealloc -- %@",[selfclass]);
    
    #endif
    
    }
    
    

    textfield의placeholder 색상을 설정하는 두 가지 방법

  • textfield의attributeplaceholder
    
      NSAttributedString*attr = [[NSAttributedStringalloc]initWithString:@" "attributes:@{NSBackgroundColorAttributeName:[UIColorwhiteColor]}];
    
    self.phoneNumTextField.attributedPlaceholder= attr;
    
    
  • 설정
  • KVC 통과
    
    [self.phoneNumTextFieldsetValue:[UIColorwhiteColor]forKeyPath:@"_placeholderLabel.textColor"];
    
    
  • 좋은 웹페이지 즐겨찾기