2013-04-24 1 views
0

동일한보기에서 많은 UI 요소에 동일한 변경 사항을 적용하는 방법은 종종 직면하는 문제입니다.많은 요소에 동일한 UI 변경 적용

내가 무엇을 찾고 있어요 것은이 파이썬 의사처럼 일하는 것이 뭔가 :이 작업을 수행 할 수있는 적절한 목표 - C의 방법을 무엇

def stylize(element): 
    # apply all the UI changes to an element 
elements = [button1, button2, button3] 
map(stylize,elements) 

(서브 클래스/I 원하지 않는 수없는 가정 그러한 UI 요소)?

답변

0

, UIAppearance을 사용하는 것이 좋습니다.

특정보기 컨트롤러의 경우 IBOutletCollection이 가장 간단한 방법입니다. IB를 사용하는 경우 그럴 수 있습니다. 그렇지 않은 경우 사용자 정의하려는 모든 버튼이있는 NSArray 변수 또는 특성을 작성한 후이를 반복 할 수 있습니다.

  1. 는, 예를 들어, 범주를 사용하여있는 UIButton에 메소드를 추가하는 파이썬 코드의 가장 직역 것 -[UIButton(YMStyling) ym_stylize]
  2. 다음으로 [@[button1, button2, button3] makeObjectsPerformSelector:@selector(ym_stylize)]으로 전화하십시오.

이것은 코코아/Obj-C 세계에서 다소 부 자연스러운 것이므로 위의 더 관용적 인 접근 방법을 따르는 것이 좋습니다. 로마에있을 때 ...

+0

그래서 로마인의 Obj-C 로마에서 할 일을, 그들은'IBOutletCollection' 사용합니까 : 여기에 내 생각을 입증하기 위해 만든 예는? – syntagma

+0

네, 그렇게 생각합니다 ;-) UIAppearance 또는 IBOutletCollection을 사용하십시오. –

0

파이썬도 모르겠다. 나는 당신의 질문을 완전히 이해하지 못했다. 나에게는 분명하지 않다.

아마도 당신은 IBOutletCollection을 찾고 있습니다.

"객체와 통신" 를 참조 이러한 상수를 사용하는 방법에 대한 자세한 내용은 IBOutletCollection

Identifier used to qualify a one-to-many instance-variable declaration so that Interface Builder can synchronize the display and connection of outlets with Xcode. You can insert this macro only in front of variables typed as NSArray or NSMutableArray. 

This macro takes an optional ClassName parameter. If specified, Interface Builder requires all objects added to the array to be instances of that class. For example, to define a property that stores only UIView objects, you could use a declaration similar to the following: 

@property (nonatomic, retain) IBOutletCollection(UIView) NSArray *views; 

For additional examples of how to declare outlets, including how to create outlets with the @property syntax, see “Xcode Integration”. 

Available in iOS 4.0 and later. 

Declared in UINibDeclarations.h. 

토론

. Interface Builder에서 액션과 아웃렛을 정의하고 사용하는 방법에 대한 자세한 내용은 Interface Builder User Guide를 참조하십시오.

확인이 링크 :

  1. UIKitConstantsReference
  2. 글로벌 응용 프로그램 스타일링에 대한
  3. Using iOS 4′s IBOutletCollection
0

당신은 단순히 NSMutableArray를 사용할 수 있다고 가정합니다.

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 20, 40)]; 
    [view1 setBackgroundColor:[UIColor blackColor]]; 
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(150, 100, 20, 40)]; 
    [view2 setBackgroundColor:[UIColor whiteColor]]; 
    UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(200, 100, 20, 40)]; 
    [view3 setBackgroundColor:[UIColor redColor]]; 

    [self.view addSubview:view1]; 
    [self.view addSubview:view2]; 
    [self.view addSubview:view3]; 

    NSMutableArray *views = [NSMutableArray arrayWithObjects:view1, view2, view3, nil]; 

    [self changeViews:views]; 
} 

-(void)changeViews:(NSMutableArray *)viewsArray { 
    for (UIView *view in viewsArray) { 
     [view setBackgroundColor:[UIColor blueColor]];//any changes you want to perform 
    } 
} 
+0

양의 대답에 댓글을 달 수 없으므로 여기에 말씀 드리겠습니다. 답변을 얻은 직후 OP 게시글에서 같은 질문을하는 것 같습니다. – AlimovAndrei

관련 문제