UI view Animations:
Several classes in the UIKIT Framework can be referred at UIKIT Faframework Fundamentals.
Inclined to build a profession as IOS Developer? Then here is the blog post on iPhone Development Certification Training.
Animation: 1
[UIview beginAnimations : nil Context : nil]; [UIView setAnimationsDuration :2 ]; Imgview . Center = Self. View .Center; [ UIView CommitAnimations];
<strong>Animation:2</strong> [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];
-->crop image[required part in the view]
Subscribe to our youtube channel to get new updates..!
-->view
CGRect CropRect = CGRectMake (100,100,100,100); CGImage Ref tmp = CGImageCreateWithImageInRect ( imgview. Image . CGImage ,CropRect); UIImage * cropImage = [UIImage imagewithCGImage :tmp]; Img view. Image = CropImage; } <strong>UILabel:-</strong>
-->// How To Create Label Dynamically
UILabel * lbl = [[ UILabel alloc] init];
-->// Setting Frame
Lbl. frame = CGRectMake (100,100,200,40);
-->// Setting Text to Label
Lbl .text = @ “hi”;
-->// Setting Font
Lbl .font = [UIFont SystemFontsize :16];
-->// Setting BackGround Color
Lbl. backgroundColor = [ UIColor red color];
-->// Setting Text Color
Lbl . textcolor = [UIColor blackColor];
-->// set Tag
Lbl . tag =1;
-->// Setting Hidden
Lbl. Hidden = No;
-->//Setting Contrast
Lbl. alpha = 1;
-->// set number of lines
Lbl . number of lines = 2;
-->// Setting Label Text Alignment
[ Lbl SetTextAlignment : UITextAlignmentCenter];
-->// Setting user interaction enabled
Lbl user interaction enabled = No;
-->// Adjust font size with in width
[ lbl . SetAdjustFontSizeToFitWidth: yes]; [self view addSubview : Lbl];
UIButton:-
-(void) viewDidLoad { UIButton * button = [ UIButton buttonWithType: UIButtonTypeRoundedRect];
-->// Setting title:
[ btn SetTitle :@ “Bttn” forState: UIControlStateNamed];
-->// Setting frame:
bttn setFrame : CGRect make(100,200,100,40);
-->// Setting Image:
[btn SetImage:[ UIImage imageNamed :@ “2.jpg”] ForState: UIControlStateNormal];
-->// Setting backGround Image:
btn set backGround Image: [UIImage imageNamed :@ “2.jpg”]; forState: UIControlStateNormal];
-->// Setting Title Color:
[btn setTitleColor : [ UIColor blackColor] ForState : UIControlStateNormal];
-->// Setting tag:
[ btn setTag :2];
-->// Set Alpha:
[btn SetAlpha :1];
-->// Set Enabled:
[ btn setEnabled : yes];
-->// set UserInteraction Enabled
[btn setUserInteractionEnabled : yes];
-->// Setting Selected:
[btn Set Selected : No];
-->// setting back ground color:
[btn setBackgroundColor :[ UIColor greenColor]]; // forState: <# UI Control State)State#>
-->// adding Target:
[btn add target: self action :@ Selector (Button Clicked forControlEvents: UIControl Event Touchup Inside];
-->// adding to Self view:
[Self view addsubview :btn]; } -(void) button Clicked { NSLog (@ “ Button Clicked”); }
-->// 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)]
-->// Setting text to text field:
[txtField setText :@ “hi”];
-->// Setting place holder:
[txtField setPlaceHolder :@ “select”];
-->// for password Security:
[txtField setSecureTextEntry: yes];
-->// Setting tag:
[txtField setTag:1];
-->// setting TextAlignment:
[txtField SetTextAlignment :UITextAlignmentCenter];
-->Setting keyboard Type:
[txtField set keyboard Type: UIkeyboardTypeDefault];
-->// set key board return type Button:
[ txtField SetReturnType: UIReturnkeyDone];
-->// Setting TextColor:
[txtField setTextColor : [ UIColor blueColor]];
-->// Setting TextFont:
[txtField SetFont: [UIFont SystemFontSize :16]]
-->// Setting textField style(custom cell)
[txtField setBorderStyle: UITextBorderStyleRoundedRect];
-->// Setting Background Image:
[ txtField SetBackgroundColor: [UIColor redColor]];
-->// Setting ClearButton:
[txtField SetClearButtonMode: UITextFieldviewModeWhileEditing];
-->// Setting Delegate:
[txtField SetDelegate : Self];
-->// Adding textField to the view
[ self view addsub view : txtField]; [txtField release];
Delegate methods:
There are three methods:
<strong>--></strong>1. (void) text FieldDidBeingEditing: (UITextField *)textField { NSLog (@ “textFieldDidBeingEditing calling”); }
-->2:
-(Bool) textField : (UITextField *) textField ShouldChangeCharacterInRange :(NSRange) range replacementString:(NSString*) String { NSLog ( @ “ ShouldChangeCharacterInRange called and setting is % @”, textField, text); Return yes; }
-->3:
-(Bool) textFieldShouldClear : ( UITextClearField *) textField { NSLog ( @ “ textField should clear called”); }
UITextView:-
.h file:-
# import @ interface UITextviewb8viewController: UIViewController { IBoutlet UITextView * textView; } -(IBAction) done clicked; @ end
. m file:-
-(void) viewDidLoad {
-->// Setting text :
txt view. text = @ “hello”;
-->// setting non- edit Mode:
txt view. Editable=No;
-->// setting back ground Color:
txtview .backgroundColor . [ UIColor grayColor];
-->// set tag:
txtView tag = 1;
-->// set delegate:
TxtView delegate = self; [ Superview Did Load]; }
# program mark UIViewText DelegateMethod:
-->1:
-(void) textviewDidBeginEditing : (UITextView)*)textview { NSLog (@ “textviewDidBeginEditing called”) }
-->2:
-(void) textviewDidBeginEditing called: (UIText view*) text view { NSLog (@ “textViewDidEndEditing called”); }
-->3:
-(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 #import @ interface TouchesViewController: UIViewController { } -(IBAction) clear click; @ end
. m file:-
-->
-(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 outlets?
. h file:-
@ interface b8ControlsviewController: UIviewController { IBoutlet UIButton * btn1, *btn2, *btn3; } -(IBAction) button Clicked : (id) Sender; @ end;
.m file:-
-->// using outlets:
-(IBAction ) button Clicked : (id) Sender { UIButton * SelectedBtn =(UIButton *) sender; If (SelectedBtn = = btn1) { } If (SelectedBtn = = btn2) { } If (SelectedBtn = = btn3) { } }
-->// 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”]) { } }
Frequently Asked iPhone Interview Questions & Answers