2011-09-06 6 views
0

enter image description here슬라이더에서 이미지를 설정하는 방법은 무엇입니까?

위의 이미지에 슬라이더 컨트롤을 사용하고 싶습니다. 사용자가 슬라이드하면 카테고리 탭이 강조 표시되고 모두 기뻐합니다. 그래서 어떻게 슬라이더 컨트롤러를 사용하여이 기능을 사용할 수 있습니까? 어떻게 슬라이더 컨트롤을 사용합니까?

답변

0
The simplest solution would be to render a UIImage behind the control to represent the track. The thumbknob can be changed with: 

[mySlider setThumbImage:[UIImage imageNamed:@"thumb_image.png"] forState:UIControlStateNormal]; 

A side-effect of this is that the track isn't rendered unless you provide your own. This, combined with the UIImage, provide you with a custom UISlider without you having to subclass anything. 
0

당신이 보여주고 컨트롤은 세그먼트 제어 그리고 당신은

UISegmentedControl* offlineSegment=[[UISegmentedControl alloc] initWithItems:[[[NSMutableArray alloc] initWithObjects:@"ON",@"OFF",nil] autorelease]]; 
    [offlineSegment setFrame:CGRectMake(210,50,90,30)]; 
    offlineSegment.tintColor=[UIColor greenColor]; 
    offlineSegment.selectedSegmentIndex=0; 

    offlineSegment.segmentedControlStyle=UISegmentedControlStyleBezeled; 
    [locationSegment setImage:[UIImage imageNamed:@"onSelected.png"] forSegmentAtIndex:0]; 
    [locationSegment setImage:[UIImage imageNamed:@"off.png"] forSegmentAtIndex:1]; 
    [offlineSegment addTarget:self action:@selector(offlineSetting:) forControlEvents:UIControlEventValueChanged]; 
    [self.view addSubview:offlineSegment]; 
    [offlineSegment release]; 

희망이 내가이 확실하지 않다 당신에게

+0

나는 이것과 함께 슬라이더가 필요합니다. – iRam11

+0

좋아, UIView 클래스를 서브 클래스해야하고 슬라이더를 그릴 필요가있다. 그런 다음 사용자 정의 구현을 사용하지 않고이 다른 것을 쉽게 얻을 수있다 – Sabby

+0

어떻게 슬라이더를 사용자 정의하고 세그먼트 컨트롤을 추가 할 수있는 코드를 줄 수 있습니까? – iRam11

0

도움이 될 것입니다이 코드 조각을 사용하여 이미지를 설정할 수 있습니다 질문 여부를 응답 할 것이다 그러나 나는이

https://github.com/samvermette/SVSegmentedControl

처럼 약간 보이는 github에이 프로젝트를 보았다
관련 문제