Blog

  • Home
  • iPhone
  • iPhone – Creating a User Interface Kit (UIKIT) – III

iPhone – Creating a User Interface Kit (UIKIT) – III

  • (4.0)
  • | 1105 Ratings

The  UIKIT Framework provides the crucial infrastructure needed to construct and manage iOS apps.

Enroll for Instructor Led Live IOS DEVELOPMENT TRAINING.

UI Switch:-

-(void)  viewDidload

{
UISwitch     * a Switch  =  [[UISwitch alloc]
InitWithFrame :  CGRectMake  (100,100,200,100)];
[ aSwitch  SetOn :   YES];
[ aSwitch  add Target  :  self
action   :   @  Selector  (Switch Changed)
ForControlEvents:   UIControlEventValueChanged];
[ self view  add sub view  :  a switch];
}
-(void)SwitchChanged
{
NSLog  ( @  “ Switch  Changed  called”);
Self .view .backgroundColor = [b8ControlViewController random color];
}
+ (UIColor     *)   random color
{
Static  Bool Seeded  = No;
If (   !seeded)
{
Seeded  =  YES;
Random  (  time  (NULL));
}
CGFloat  red  =   ( CGFloat)  random ()/ ( CGFloat) RAND . MAX;
CGFloat  blue  =  (CGFloat) random  ()/(CGFloat) RAND MAX;
CGFloat green  =   (CGFloat) random()/(CGFloat ) RAND MAX;
NSLog (@  “  color  red  =  %  f green  =     %  f   blue  =   %   f”, Red, green, blue);
return  [ UIColor  colorWithRed :red    green :green blue :blue alpha:1.of];
}


UI SegmentControl:-

-(void) viewDidLoad
{


-->segment Control:

NSArray      *a Array    =[NSArray    arraywithObjects: @ “first”,  @  “Second”, nil];
UISegmentedControl  *Segment=
[[ UISegmentedControl alloc]  initWithItems  : aArray];

--> Set frame:

Segments1 frame =   CGRectMake  (100,200,200,50.);

-->Set Target:

[Segment1  addTarget  :    self
Action  :   @  Selector   ( SegmentChanged)
ForControlEvents:  UIControlEventValueChanged];

-->Set  Images  to Segments:

[ segments1 set Image : [UIImage imageNamed : @ “1.jpg”]
For segmentAtIndex :0];

--> Set Title for each  Segment:

[ segment1   set Title: @ “one” for SegmentAtIndex:0];

--> set tag:

[ Segment1   setTag :1];

-->  set tint  Color:

[ Segment1    setTintColor   : [UIColor    blackColor]];

-->adding  to view:

[self view  addSubView:  Segments1];
[segments1     release];
}
-(IBAction) SegmentControl changed:  (id) Sender
{
UISegmentedControl   *segment   =(UISegmentedControl   *)sender;
If(segment.  SelectedSegmentIndex  = = 0)
{
}
else if ( Segment. SelectedSegmentIndex = = 1)
{
}
}

UISlider  :-

-(void)  viewDidload
{
UISlider     *  aSlider   =   [[ UISlider alloc]
InitWithFrame :  CGRectMake  (50,200,200,50)];

-->  setting  minimum value:

[ aSlider setMinimumValue:0];


--> setting maximum value:

[ aSlider setMaximumValue: 100];

--> setting initial value:

[ aSlider setValue  : 50];

--> setting  minimum value image:

[ aSlider setMinimumValueImage: [UIImage    imageNamed :@ “1.jpg]];

-->setting  maximum value image:

[ aSlider setMaximumvalueImage: [UIImage imageNamed:  @  “2.jpg”]];

--> adding target:

[ aSlider  addTarget   :  self
          Action       :  @ selector (SliderChanged:)
     ForControlEvent   :  UIControlEventValueChanged];
[ self view  add sub  view :  aSlider];
[ a slider       release];
UILabel    *lbl  =   [[ UILabel  alloc]  initWithFrame : CGRectMake             (260,200,50,40.)];
                     [lbl  setBackgroundColor  : [ UIColor  clear color]];
                     [ lbl setText : @ “50”];
                     [ self view addSubView  :  lbl];
                     [lbl release];
                     [ Super viewDidLoad];
         }
-(void) SliderChanged : (id) Sender
 {
UISlider     * bSlider   =   (  UISlider     *)   sender;
Lbl. Text  =   [  NSString StringWith Format: @ “%.0.of”, bSlider .value];
}


UIActivityIndicatorView:-

-(void) viewDidLoad
{
UIActivityIndicatorView *activity  =
[[UIActivityIndicatorView alloc] init];
[ activity setActivityviewStyle:
UIActivityIndicatorViewStyleWhite];
// activity center =  self  view center;
Activity. Frame  =   CGRectMake   self. View  . center;
Activity .frame  = CGRectMake (self view center .x, self. View. Center .y, 40,40);
[ activity setHidesWhenStopped :YES];
[ activity  startAnimating];
[ self view addSub view : activity];
[activity release];
}


UIProgress View:-

<strong>.h file:-
</strong># import  
@ interface slider view controller: UI view controller
{
Float  value;
UIProgressView        *progress;
}
@ end

<strong>. m file:-
</strong>-(void) viewDidLoad
{
Progress   = [[ UIProgressView    alloc] initWithFrame:
                          CGRectMake  (100,300,200,40)];
[ self view addSub view: Progress];
[ NSTimer ScheduledTimerWithTimeInterval :0.1
                  Target    :  self
                Selector    :  @ selector ( time Change)                         
               UserInfo     :   nil
                 Repeats    :   yes];
}
-(void) timer changed
{
Value+ = 0.1;
NSLog  ( @  “  timer changed called and value is % f”, value);
Int x= (int) value;
If (x = = 1)
Value = 0;
[ progress set progress : value];
}

UIProgressView :-

. h file:-

# import  
@   interface  SliderViewController : UIViewController
{
Float value;
UIProgress view       * progress;
}
@ end

. m file:-

-(void) viewDidLoad
{
Progress  =  [[ UIProgressview  alloc] initWithFrame:
                         CGRectMake  (100,300,200,40)];
[ self view addSubview : Progress];
NSTimer scheduledTimerWithTimeInterval   : 0.1
               Target  :    self
                 
             Selector  :  @  selector( time Change)
            UserInfo   :  nil
             Repeats   :   yes];
}
-(void) timer changed
{
Value  +   =  0.1;
NSLog   (@  “ timer changed  called and value is % f”, value);
Int x = (int) value;
If (x = = 1)
Value   = 0;
[ progress SetProgress :   Value];
}

Frequently Asked iPhone Interview Questions & Answers


Subscribe For Free Demo

Free Demo for Corporate & Online Trainings.

Ravindra Savaram
About The Author

Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.


DMCA.com Protection Status

Close
Close