view.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property UISegmentedControl *main,*hv,*subs;
@property UIButton *reset,*add1,*add2;
@property UILabel *rl,*gl,*bl,*ml,*label1;
@property UISlider *rs,*gs,*bs,*ms;
@property UIView *mv;
@property UITextField *rt,*gt,*bt,*mt,*dt;
@property UIScrollView *sv;
@property UISwitch *switch1;
@property UIButton *button1;
@property NSMutableArray * array;
@end
view.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
int i=0;
int x=20,y=20;
- (void)viewDidLoad {
[super viewDidLoad];
[self uielements];
self.array=[[NSMutableArray alloc]init];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)uielements
{
//segmentedControl
self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"11.jpg"] ];
self.subs = [[UISegmentedControl alloc]init ];
self.subs.frame=CGRectMake(20, 400, 330, 30);
self.subs.apportionsSegmentWidthsByContent=YES;
[self.view addSubview:self.subs];
self.main=[[UISegmentedControl alloc]initWithItems:@[@"Label",@"Switch",@"Button"]];
self.main.frame=CGRectMake(50, 50, 150, 30);
[self.view addSubview:self.main];
[self.main addTarget:self action:@selector(allMethods) forControlEvents:UIControlEventValueChanged];
self.hv=[[UISegmentedControl alloc]initWithItems:@[@"Horizontal",@"Vertical",@"Zig Zag"]];
self.hv.frame=CGRectMake(50, 100, 200, 30);
[self.view addSubview:self.hv];
[self.hv addTarget:self action:@selector(allMethods) forControlEvents:UIControlEventValueChanged];
//label
self.rl=[[UILabel alloc]initWithFrame:CGRectMake(30, 150, 30, 30)];
self.rl.text=@"R";
self.rl.textColor=[UIColor redColor];
[self.view addSubview:self.rl];
self.gl=[[UILabel alloc]initWithFrame:CGRectMake(30, 200, 30, 30)];
self.gl.text=@"G";
self.gl.textColor=[UIColor greenColor];
[self.view addSubview:self.gl];
self.bl=[[UILabel alloc]initWithFrame:CGRectMake(30, 250, 30, 30)];
self.bl.text=@"B";
self.bl.textColor=[UIColor blueColor];
[self.view addSubview:self.bl];
self.ml=[[UILabel alloc]initWithFrame:CGRectMake(30, 300, 30, 30)];
self.ml.text=@"M";
[self.view addSubview:self.ml];
//slider
self.rs=[[UISlider alloc]initWithFrame:CGRectMake(70, 150, 100, 30)];
self.rs.minimumValue=0;
self.rs.maximumValue=255;
self.rs.thumbTintColor=[UIColor redColor];
[self.rs addTarget:self action:@selector(rgbColor:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.rs];
self.gs=[[UISlider alloc]initWithFrame:CGRectMake(70, 200, 100, 30)];
self.gs.minimumValue=0;
self.gs.maximumValue=255;
self.gs.thumbTintColor=[UIColor greenColor];
[self.gs addTarget:self action:@selector(rgbColor:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.gs];
self.bs=[[UISlider alloc]initWithFrame:CGRectMake(70, 250, 100, 30)];
self.bs.minimumValue=0;
self.bs.maximumValue=255;
self.bs.thumbTintColor=[UIColor blueColor];
[self.bs addTarget:self action:@selector(rgbColor:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.bs];
self.ms=[[UISlider alloc]initWithFrame:CGRectMake(70, 300, 100, 30)];
self.ms.minimumValue=0;
self.ms.maximumValue=1000;
self.ms.thumbTintColor=[UIColor orangeColor];
[self.ms addTarget:self action:@selector(rgbColor:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.ms];
//textField
self.rt=[[UITextField alloc]initWithFrame:CGRectMake(180, 150, 45, 30)];
self.rt.borderStyle=UITextBorderStyleBezel;
self.rt.backgroundColor=[UIColor grayColor];
[self.view addSubview:self.rt];
self.gt = [[UITextField alloc]initWithFrame:CGRectMake(180, 200, 45, 30)];
self.gt.borderStyle=UITextBorderStyleBezel;
self.gt.backgroundColor=[UIColor grayColor];
[self.view addSubview:self.gt];
self.bt=[[UITextField alloc]initWithFrame:CGRectMake(180, 250, 45, 30)];
self.bt.borderStyle = UITextBorderStyleBezel;
self.bt.backgroundColor=[UIColor grayColor];
[self.view addSubview:self.bt];
self.mt=[[UITextField alloc]initWithFrame:CGRectMake(180, 300, 45, 30)];
self.mt.borderStyle =UITextBorderStyleBezel;
self.mt.backgroundColor=[UIColor grayColor];
[self.view addSubview:self.mt];
self.dt=[[UITextField alloc]initWithFrame:CGRectMake(80, 350, 150, 30)];
self.dt.placeholder=@"number";
self.dt.borderStyle=UITextBorderStyleLine;
[self.view addSubview:self.dt];
//view
self.mv=[[UIView alloc]initWithFrame:CGRectMake(250, 150, 120, 150)];
self.mv.backgroundColor=[UIColor blackColor];
[self.view addSubview:self.mv];
//button
self.reset=[UIButton buttonWithType:UIButtonTypeSystem];
self.reset.frame=CGRectMake(280, 100, 50, 30);
[self.reset setTitle:@"Reset" forState:UIControlStateNormal];
self.reset.backgroundColor=[UIColor purpleColor];
[self.reset addTarget:self action:@selector(remove) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.reset];
self.add1=[UIButton buttonWithType:UIButtonTypeSystem];
self.add1.frame=CGRectMake(250, 300, 50, 30);
[self.add1 setTitle:@"ADD" forState:UIControlStateNormal];
self.add1.backgroundColor=[UIColor purpleColor];
[self.add1 addTarget:self action:@selector(segmentCreate) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.add1];
self.add2=[UIButton buttonWithType:UIButtonTypeSystem];
self.add2.frame=CGRectMake(250, 350, 50, 30);
[self.add2 setTitle:@"ADD" forState:UIControlStateNormal];
self.add2.backgroundColor=[UIColor purpleColor];
[self.add2 addTarget:self action:@selector(segmentCreate1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.add2];
//scrollview
self.sv=[[UIScrollView alloc]initWithFrame:CGRectMake(20, 450, 350,200)];
self.sv.contentSize=CGSizeMake(5000, 5000);
self.sv.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"1.jpg"]];
[self.view addSubview:self.sv];
}
-(void)rgbColor:(UISlider *)sender
{
self.rt.text=[NSString stringWithFormat:@"%i",(int)self.rs.value];
self.gt.text=[NSString stringWithFormat:@"%i",(int)self.gs.value];
self.bt.text=[NSString stringWithFormat:@"%i",(int)self.bs.value];
self.mt.text=[NSString stringWithFormat:@"%i",(int)self.ms.value];
self.mv.backgroundColor=[[UIColor alloc]initWithRed:self.rs.value/255.f green:self.gs.value/255.f blue:self.bs.value/255.f alpha:1.0];
}
-(void)segmentCreate
{
[self.subs insertSegmentWithTitle:self.mt.text atIndex:0 animated:YES];
[self.subs addTarget:self action:@selector(allMethods) forControlEvents:UIControlEventTouchUpInside];
}
-(void)segmentCreate1
{
[self.subs insertSegmentWithTitle:self.dt.text atIndex:0 animated:YES];
[self.subs addTarget:self action:@selector(allMethods) forControlEvents:UIControlEventTouchUpInside];
}
-(void)allMethods
{
int a=[[self.subs titleForSegmentAtIndex:self.subs.selectedSegmentIndex]intValue];
if (self.main.selectedSegmentIndex==0 && self.hv.selectedSegmentIndex==0)
{
[self remove];
for (i=0; i<=a ; i++)
{
self.label1 = [[UILabel alloc]init];
self.label1.frame=CGRectMake(x, y, 30, 30);
self.label1.text=[NSString stringWithFormat:@"%i",i];
self.label1.backgroundColor=[UIColor greenColor];
x=x+40;
if (x>450)
{
y=y+40;
x=20;
}
[self.sv addSubview:self.label1];
[self.array addObject:self.label1];
}
}
else if (self.main.selectedSegmentIndex==0 && self.hv.selectedSegmentIndex==1)
{
[self remove];
for (i=0; i<=a; i++)
{
self.label1=[[UILabel alloc]init];
self.label1.frame=CGRectMake(x, y, 30, 30);
self.label1.text=[NSString stringWithFormat:@"%i",i];
self.label1.backgroundColor=[UIColor blueColor];
y=y+40;
if(y>1000)
{
x=x+40;
y=20;
}
[self.sv addSubview:self.label1];
[self.array addObject:self.label1];
}
}
else if (self.main.selectedSegmentIndex==1 && self.hv.selectedSegmentIndex==0)
{
[self remove];
for (i=0; i<=a; i++) {
self.switch1=[[UISwitch alloc]initWithFrame:CGRectMake(x, y, 30, 30)];
x=x+50;
if (x>450) {
y=y+50;
x=20;
}
[self.sv addSubview:self.switch1];
[self.array addObject:self.switch1];
}
}
else if (self.main.selectedSegmentIndex==1 && self.hv.selectedSegmentIndex==1)
{
[self remove];
for (i=0; i<=a; i++) {
self.switch1=[[UISwitch alloc]initWithFrame:CGRectMake(x, y, 30, 30)];
y=y+50;
if (y>1000) {
x=x+50;
y=20;
}
[self.sv addSubview:self.switch1];
[self.array addObject:self.switch1];
}
}
else if (self.main.selectedSegmentIndex==2 && self.hv.selectedSegmentIndex==0)
{
[self remove];
for (i=0; i<=a; i++)
{
self.button1 = [UIButton buttonWithType:UIButtonTypeSystem];
[self.button1 setTitle:[NSString stringWithFormat:@"%i",i] forState:UIControlStateNormal];
self.button1.frame=CGRectMake(x, y, 30, 30);
self.button1.backgroundColor=[UIColor blackColor];
x=x+40;
if (x>450) {
y=y+40;
x=20;
}
[self.sv addSubview:self.button1];
[self.array addObject:self.button1];
}
}
else if (self.main.selectedSegmentIndex==2 && self.hv.selectedSegmentIndex==1)
{
[self remove];
for (i=0; i<=a; i++) {
self.button1 = [UIButton buttonWithType:UIButtonTypeSystem];
[self.button1 setTitle:[NSString stringWithFormat:@"%i",i] forState:UIControlStateNormal];
self.button1.frame=CGRectMake(x, y, 30, 30);
self.button1.backgroundColor=[UIColor greenColor];
y=y+40;
if (y>1000) {
x=x+40;
y=20;
}
[self.sv addSubview:self.button1];
[self.array addObject:self.button1];
}
}
else if (self.main.selectedSegmentIndex==0 && self.hv.selectedSegmentIndex==2)
{
[self remove];
for (i=0; i<=a; i++)
{
BOOL isDecrement=NO;
self.button1 = [UIButton buttonWithType:UIButtonTypeSystem];
[self.button1 setTitle:[NSString stringWithFormat:@"%i",i] forState:UIControlStateNormal];
self.button1.frame=CGRectMake(x, y, 30, 30);
self.button1.backgroundColor=[UIColor greenColor];
if (isDecrement==NO)
{
x=x+40;
}
else{
x=x-40;
}
if (x>350) {
isDecrement=YES;
x=x-40;
y=y+40;
}
// if (x<40) {
// isDecrement=NO;
// x=x+40;
// y=y+40;
//
// }
[self.sv addSubview:self.button1];
[self.array addObject:self.button1];
}
}
}
-(void)remove
{
for (i=0; i<self.array.count; i++) {
UILabel * lab = [self.array objectAtIndex:i];
UISwitch *swt=[self.array objectAtIndex:i];
UIButton *btn=[self.array objectAtIndex:i];
[lab removeFromSuperview];
[swt removeFromSuperview];
[btn removeFromSuperview];
x=20;
y=20;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up here with your email
ConversionConversion EmoticonEmoticon