मैं सिर्फ इस दृश्य बनाया है, और आप सवाल
आशा है कि यह मदद करता है
ज फ़ाइल देखा:
#import <UIKit/UIKit.h>
@interface EDSwitch : UIView
{
UIButton* onButton,*offButton;
UIImageView* bg;
}
- (id)initWithText:(NSString*)on andText:(NSString*)off andDelegate:(id)delegate andOnSelector:(SEL)onSelector andOffSelector:(SEL)offSelector andBackgroundImage:(UIImage*)bgImage andStartingValue:(BOOL)b;
@end
और .m फ़ाइल:
#import "EDSwitch.h"
@implementation EDSwitch
- (id)initWithText:(NSString*)on andText:(NSString*)off andDelegate:(id)delegate andOnSelector:(SEL)onSelector andOffSelector:(SEL)offSelector andBackgroundImage: (UIImage*)bgImage andStartingValue:(BOOL)b
{
self = [super initWithFrame:CGRectZero];
if (self) {
UILabel* onLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 8, 50, 20)];
onLabel.text = on ;
onLabel.tag = 1;
onLabel.font = [UIFont fontWithName:kCalibri size:15];
onLabel.textAlignment = UITextAlignmentCenter;
onLabel.textColor = [UIColor colorFromHexString:@"#009dd0"];
onLabel.backgroundColor = [UIColor clearColor];
[onLabel sizeToFit];
[onLabel setWidth:onLabel.frame.size.width + 4];
UILabel* offLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 8, 50, 20)];
offLabel.text = off ;
offLabel.tag = 1;
offLabel.textAlignment = UITextAlignmentCenter;
offLabel.font = [UIFont fontWithName:kCalibri size:15];
offLabel.textColor = [UIColor colorFromHexString:@"#009dd0"];
offLabel.backgroundColor = [UIColor clearColor];
[offLabel sizeToFit];
[offLabel setWidth:offLabel.frame.size.width + 4];
float high = MAX([offLabel.text sizeWithFont:offLabel.font].width,[onLabel.text sizeWithFont:onLabel.font].width) + 10;
onButton = [UIButton buttonWithType:UIButtonTypeCustom];
[onButton addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventTouchUpInside];
[onButton addTarget:delegate action:onSelector forControlEvents:UIControlEventTouchUpInside];
offButton = [UIButton buttonWithType:UIButtonTypeCustom];
[offButton addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventTouchUpInside];
[offButton addTarget:delegate action:offSelector forControlEvents:UIControlEventTouchUpInside];
[onButton setWidth:high];
[onButton setX:0];
[onButton addSubview:onLabel];
[onLabel setWidth:high];
[onLabel setX:0];
[offButton setWidth:high];
[offButton addSubview:offLabel];
[offButton setX:high];
[offLabel setWidth:high];
[offLabel setX:0];
bg = [[UIImageView alloc] initWithImage:bgImage];
self.frame = CGRectMake(200, 200 , (high*2), 34);
self.layer.borderColor = [[[UIColor colorFromHexString:@"#009dd0"] colorWithAlphaComponent:0.5] CGColor];
self.layer.borderWidth = 0.5;
self.layer.cornerRadius = 5;
[self setX:[UIApplication sharedApplication].keyWindow.frame.size.width - self.frame.size.width - 8];
[self addSubview:bg];
[bg setWidth:[self getWidth]];
[bg setHeight:[self getHeight]];
[self addSubview:onButton];
[self addSubview:offButton];
[onButton setHeight:[self getHeight]];
[offButton setHeight:[self getHeight]];
if(b){
[onButton setBackgroundColor:[UIColor clearColor]];
[offButton setBackgroundColor:[UIColor whiteColor]];
}
else{
[onButton setBackgroundColor:[UIColor whiteColor]];
[offButton setBackgroundColor:[UIColor clearColor]];
}
}
return self;
}
-(void)toggled:(UIButton*)sender{
if(sender == onButton){
UILabel* l = (UILabel*)[onButton viewWithTag:1];
l.textColor = [UIColor grayColor];
[onButton setBackgroundColor:[UIColor clearColor]];
l = (UILabel*)[offButton viewWithTag:1];
l.textColor = [UIColor colorFromHexString:@"#009dd0"];
[offButton setBackgroundColor:[UIColor whiteColor]];
}
else{
UILabel* l = (UILabel*)[offButton viewWithTag:1];
l.textColor = [UIColor grayColor];
[offButton setBackgroundColor:[UIColor clearColor]];
l = (UILabel*)[onButton viewWithTag:1];
l.textColor = [UIColor colorFromHexString:@"#009dd0"];
[onButton setBackgroundColor:[UIColor whiteColor]];
}
}
@end
उपयोग:
[[UIApplication sharedApplication].keyWindow addSubview:[[EDSwitch alloc] initWithText:@"aksdjaksdjh" andText:@"dasjdsaj" andDelegate:self andOnSelector:@selector(logon) andOffSelector:@selector(logoff) andBackgroundImage:[UIImage imageNamed:@"toggleBottom.png"] andStartingValue:YES]];
लाइव लंबी और समृद्ध,
eiran
इस कि मैं अपने प्रबंधकों को दिखा सकते हैं करने के लिए कोई सबूत/आधिकारिक बयान है? – Tomen
ऐप स्टोर में लगभग हर ऐप इसका सबूत है। – lfalin
@lfalin, ठीक है कि यह एक असाधारण का थोड़ा सा है। आप वास्तव में नहीं जानते कि दुकान पर अनुमोदित ऐप्स वास्तव में स्रोत कोड के बिना 'UISwitch' को अनुकूलित कर रहे हैं। वे ऐप्स 'UIButton' या' UISlider' या कुछ और अनुकूलित कर सकते हैं। सवाल विशेष रूप से 'यूआईएसविच' के बारे में था और मुझे लगता है कि पोस्टर क्या प्राप्त कर रहा था यह था कि कुछ अनुकूलन निजी एपीआई का उपयोग कर सकता है या नहीं। मैंने बाद में ओएस संस्करणों में परिवर्तित गैर-दस्तावेज सुविधाओं पर निर्भर नियंत्रणों को अनुकूलित करने के लिए वहां उदाहरण भी पाए हैं, और इस प्रकार तोड़ दिया। लेकिन, उन्हें ऐप्पल द्वारा मेरे ऐप्स में अनुमोदित किया गया था। – Nate