Mindmajix

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

UI View Animations:-

Several classes in the UIKIT Framework can be referred at UIKIT Framework Fundamentals.

Animation: 1

[UIview  beginAnimations   :  nil   Context   :  nil];
[UIView     setAnimationsDuration   :2 ];
Imgview  . Center   =   Self. View .Center;
[  UIView   CommitAnimations];
Animation:2
[UIView    beingAnimation:  nil   Context  :  nil];
[UIView   setAnimationDuration    :2];
[  UIView   SetAnimationTransition:  UIViewAnimation
                        Transition  (urlDown  for view:
                        Img  view:  cache:  yes];
Imgview  .   Center  =  self    .view. Center.
[UIview    CommitAnimations ];

Animation:-3

[ UIView beingAnimation :nil  Context :nil];
[UIView   SetAnimationDuration :2];
[UIView   SetAnimationDelay  :2];
[UIview   SetAnimationTransition:
[UIview  AnimationTransitionCurlDownforView:  imgview  cache : yes];
Imgview . center  =  Self  .   view  . center;
[UIview   CommitAnimations];

Animation:4

[UIView   beginAnimation  :nil   Context :nil];
[UIView  SetAnimationDuration :2];
[UIView   SetAnimationTransition:
 UIViewAnimationTransition 
               FlipFromLeftforView:
               Self .View      cache :yes];
[UIview  CommitAnimations];

 Animation:5

Img view .alpha=  0;
[UIView   beingAnimation    :  nil    Context  :nil];
[UIView   SetAnimationDuration  :2];
Imgview . alpha   =1;
[UIview   CommitAnimations];

Rotate image:-

[UIView beingAnimation :nil  Context :nil];
[UI view   setAnimationDuration  :2];
CGAffineTransform      transform = img view .transform;
              transform  =   CGAffineTransformRotate (transform,180/4)
Imgview  . transform    =       transform;
[  UIView    CommitAnimations];

Capture 14Capture 15crop image[required part in the view]

                                                       Capture 15view

CGRect    CropRect    =   CGRectMake  (100,100,100,100);
CGImage  Ref   tmp  =    CGImageCreateWithImageInRect
(  imgview.   Image  .  CGImage ,CropRect);
UIImage   *  cropImage    =  [UIImage  imagewithCGImage   :tmp];
Img view.  Image  =   CropImage;
}

UILabel:-

Capture 15// How  To Create Label  Dynamically

UILabel   * lbl    =   [[  UILabel  alloc]  init];

Capture 15// Setting  Frame

Lbl. frame =   CGRectMake  (100,100,200,40);

Capture 15// Setting Text  to Label

Lbl .text   =  @ “hi”;

Capture 15// Setting Font

Lbl .font   =   [UIFont  SystemFontsize  :16];

Capture 15// Setting BackGround Color

Lbl.  backgroundColor  =  [   UIColor red color];

Capture 15// Setting  Text  Color

Lbl .  textcolor   =    [UIColor   blackColor];

Capture 15// set   Tag

Lbl . tag  =1;

Capture 15// Setting   Hidden

Lbl. Hidden  =  No;

Capture 15//Setting  Contrast

Lbl.  alpha  =  1;

Capture 15// set  number  of lines

Lbl . number of lines  =  2;

Capture 15// Setting  Label Text  Alignment

[  Lbl SetTextAlignment  :  UITextAlignmentCenter];

Capture 15// Setting  user  interaction  enabled

Lbl  user  interaction enabled  =  No;

Capture 15// Adjust font  size   with  in width

[  lbl . SetAdjustFontSizeToFitWidth:  yes];
[self view  addSubview  :  Lbl];

UIButton:-

-(void) viewDidLoad
 {
UIButton    *  button  = [ UIButton   buttonWithType:
                           UIButtonTypeRoundedRect];


Capture 15// Setting title:

[  btn SetTitle :@  “Bttn” forState: UIControlStateNamed];

Capture 15// Setting frame:

bttn setFrame :  CGRect make(100,200,100,40);

Capture 15// Setting Image:

[btn SetImage:[ UIImage imageNamed  :@  “2.jpg”]
                ForState: UIControlStateNormal];

Capture 15// Setting backGround Image:

btn  set  backGround Image:  [UIImage   imageNamed  :@ “2.jpg”];
                  forState:  UIControlStateNormal];

Capture 15// Setting  Title  Color:

[btn  setTitleColor    :  [  UIColor  blackColor]

                    ForState  :   UIControlStateNormal];

Capture 15// Setting  tag:

[  btn  setTag  :2];

Capture 15// Set Alpha:

[btn  SetAlpha :1];

Capture 15// Set Enabled:

[  btn  setEnabled  : yes];

Capture 15// set UserInteraction Enabled

[btn  setUserInteractionEnabled   : yes];

Capture 15// Setting Selected:

[btn   Set Selected : No];

Capture 15// setting back ground color:

[btn setBackgroundColor  :[  UIColor   greenColor]];
              // forState:  <# UI Control State)State#>

Capture 15// adding  Target:

[btn  add target: self action  :@ Selector  (Button Clicked
forControlEvents: UIControl  Event  Touchup Inside];

Capture 15// adding to Self  view:

[Self view addsubview  :btn];
}
-(void) button Clicked
{
NSLog (@ “ Button Clicked”);
}

Capture 15// How to get an element using tag

UIButton   *tagbtn =   ( UIButton *) self view.
                        ViewWithtag:3];
[tag btn setTitle :@  “  TagBtn”  for state:
                        UIControlStateNormal];

UITextField :-

UITextField  *  textField  =  [[UITextField  alloc]

InitWithFrame :    CGRectMake  (100,100,100,40)]

Capture 15// Setting  text to text  field:

[txtField  setText :@ “hi”];

Capture 15// Setting place holder:

[txtField  setPlaceHolder  :@  “select”];

Capture 15// for password  Security:

[txtField  setSecureTextEntry: yes];

Capture 15// Setting tag:

[txtField     setTag:1];

Capture 15// setting TextAlignment:

[txtField  SetTextAlignment  :UITextAlignmentCenter];

Capture 15Setting keyboard  Type:

[txtField  set  keyboard Type: UIkeyboardTypeDefault];

Capture 15// set key board return type Button:

[ txtField  SetReturnType:  UIReturnkeyDone];

Capture 15// Setting  TextColor:

[txtField   setTextColor  : [  UIColor   blueColor]];

Capture 15// Setting TextFont:

[txtField  SetFont: [UIFont   SystemFontSize :16]]

Capture 15// Setting textField style(custom cell)

[txtField  setBorderStyle: UITextBorderStyleRoundedRect];

Capture 15// Setting Background Image:

[ txtField   SetBackgroundColor:  [UIColor  redColor]];

Capture 15// Setting ClearButton:

[txtField SetClearButtonMode:
 UITextFieldviewModeWhileEditing];

Capture 15// Setting Delegate:

[txtField SetDelegate :  Self];

Capture 15// Adding textField to the view

[ self  view  addsub view  :  txtField];
                   [txtField   release];

Delegate methods:

There are three methods:

Capture 151. (void) text FieldDidBeingEditing:  (UITextField  *)textField
      {
      NSLog (@  “textFieldDidBeingEditing calling”);
      }

Capture 152:

-(Bool)  textField :    (UITextField  *)  textField
ShouldChangeCharacterInRange  :(NSRange)
range  replacementString:(NSString*) String
{
NSLog (  @  “  ShouldChangeCharacterInRange  called
            and setting is % @”, textField, text);
     Return  yes;
}

Capture 153:

-(Bool)  textFieldShouldClear :  ( UITextClearField *) textField
{
NSLog (   @  “  textField should clear  called”);

}

 

UITextView:-

.h file:-

#   import  <UIKIT/UIKIT .h>
@  interface UITextviewb8viewController:  UIViewController
{
IBoutlet  UITextView   *  textView;
}
-(IBAction) done clicked;
@ end

. m file:-

-(void)  viewDidLoad
{

Capture 15// Setting text :

txt view. text  =  @  “hello”;

Capture 15// setting non- edit Mode:

txt view. Editable=No;

Capture 15// setting back ground Color:

txtview .backgroundColor . [ UIColor grayColor];

Capture 15// set tag:

txtView  tag   =  1;

Capture 15// set delegate:

TxtView  delegate   =   self;
[  Superview Did Load];
}

# program mark UIViewText DelegateMethod:

Capture 151:

-(void) textviewDidBeginEditing  :  (UITextView)*)textview
{
NSLog (@ “textviewDidBeginEditing called”)
}

Capture 152:

-(void) textviewDidBeginEditing called:  (UIText view*) text view
{
NSLog   (@ “textViewDidEndEditing called”);
}

Capture 153:

-(void) textviewDidChange:(UIText*) textview
{
  NSLog (@ “textview Did Change called and text is % @ text view text);
}
-(IBAction) done clicked
    {
    [txt view resign FirstResponder];
  }

UITouches:-

. h file:-

# import <UIKIT/UIKIT .h>
#import  <quartz core/ quartz core . h>
@ interface TouchesViewController: UIViewController
  {
  }
 -(IBAction) clear click;
@ end

. m file:-

Capture 15

-(void) touches Begin:  (NSSet  *) touches withEvent :
                                              (UIEvent    *) Event
{
// NSLog  (  @  “  touches began called”);
UITouch     * a Touch  =  [touches any Object];
NSLog ( @ “ the point is (% 0.of, %0.of),pnt .x, pnt .y);
UILabel      *  a lbl = [[ UIlabel alloc]     initWithFrame:
                         CGRectMake  (pnt . x, pnt .y,  6.6)];
[ albl    setBackgroundColor:  [ UI color red Color]];
albl layer. CornerRadius  =  3;
[ self View addSubView : a lbl];
[ a lbl release];
}
à
-(void)  touchesMoved  (NSSet   *) touches with Event( UIEvent  *)  event
{
//  NSLog (@  “ touches Moved  called”);
UITouch    *    a Touch   =    [  touches  any object ];
CGPoint pnt  =  [a Touche   locationInview  :self  view   ];
NSLog (   @  “  touches  any point is (%  0. Of , % 0.of)”,pnt .x ,  pnt .y);
[  UILabel    *  a lbl    =    [[UILabel  alloc ]
InitWithFrame :  CGRect  make (pnt .x, pnt. Y)
[a lbl  SetBackgroundColor: [UIColor redcolor]];
albl layer Corner Radius  =   3;
[self   View   addSubview  : a lbl];
[ a lbl, release  ];
}
à
-(void) touchesEnded :  (NSSet     *)   touches   With  Event   :(UIEvent    *)    event
{
NSLog (   @  “Touches Ended called”)
UI Touch   *  a Touch   = [touches   anyObject];
CGPoint pnt   =  [  aTouch  location In View   :  self  view];
NSLog  (  @  “the point is (o. of,% 0. Of)”,   pnt .x , pnt .y);
UILabel     * a lbl   =   [[ UILabel  alloc]   init  WithFrame:
                                       CGRectMake  (pnt  .x ,  pnt.y,   6,6)];
[a Lbl    SetBackgroundColor   :  [UIColor   redColor]];
aLbl . layer  . CornerRadius  =3;
 [  self .view   addSub view   :add];
 [ a Lbl  release];
}
-(IBAction) Clear click
{
NSArray    * subviews   =  [Self  . View      SubViews];
For (UIView     *  view in SubView)
{
If (    ui  is kindofClass :  [  UINavigation Bar  class]])
    [  view   remove  FromSuperView];
}

Q: How to assign single action to the multiple out lets?

. h file:-

@  interface   b8ControlsviewController: UIviewController
{
    IBoutlet   UIButton    *  btn1,  *btn2, *btn3;
}
   -(IBAction)  button Clicked  :  (id)  Sender;
@  end;

.m file:-

Capture 15// using outlets:

-(IBAction  )   button   Clicked :  (id) Sender
{
UIButton    *  SelectedBtn    =(UIButton     *)  sender;
If (SelectedBtn      = = btn1)
{
}
If (SelectedBtn  = =  btn2)
{
}
If (SelectedBtn  = = btn3)
{
}
}

Capture 15// Using  Tags:

-(IBAction)  button clicked  :  (id)  sender
 {
UIButton      *  selected  Btn  =(UIButton      *)sender
If (SelectedBtn  .tag  = = 1)
   {
   }
If (SelectedBtn  tag  = =  2)
{
}
If (SelectedBtn   tag   = =  3)
{
}
      }

// Using  Title:

-(  IB Action)   buttonClicked  :  (id)  sender
   {
UIButton   * selected Btn   =  (UIButton      *)   sender;
If ([SelectedBtn.   titleLabel. Text  is EqualToString :  @  “btn1”])
{
}
If ([  SelectedBtn .  titleLabel.  Text is EqualToString  :  @ “btn2”])
{
}
If ([SelectedBtn .  titleLabel.  Text  is Equal  to string  :   @  “btn3”])
{
}
}

 

0 Responses on iPhone – Creating a User Interface Kit (UIKIT) – II"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.