`
cenphoenix
  • 浏览: 161431 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

iPhone Coding Tutorial – Inserting A UITextField In A UIAlertView

阅读更多

This will be a simple tutorial showing you how to put a UITextField in a UIAlertView. This is simple and just a couple lines if code. You will learn CGAffineTransform and coding UITextField programmatically.

Heres a screenshots of what we should get.



 So lets go ahead and get started…

1. Create A New View Based Application

You can name it whatever you want, I am gonna name it TextFieldInAlert.

2. Implementing The Code

Jump in the viewcontroller.m or if you called it TextFieldInAlert then TextFieldInAlert.m Now find the -(void)viewDidLoad method. Uncomment it and put this code in there.

- (void)viewDidLoad { [super viewDidLoad]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Enter Name Here” message:@”this gets covered!” delegate:self cancelButtonTitle:@”Dismiss” otherButtonTitles:@”OK!”, nil]; UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)]; [myTextField setBackgroundColor:[UIColor whiteColor]]; [alert addSubview:myTextField]; [alert show]; [alert release]; [myTextField release]; }


 So we are basically calling a UIAlertView and then we are adding the UITextField programmatically. You might have noticed in the message part of the UIAlertView we put “this gets covered!”, if we didn’t put that sentence then the alerts buttons would go up more and the UITextField will be messed. You can try taking that line out and see what happens. Now Build and Run the app. Now you got the UITextField to be inside the UIAlertView. Now try tapping the UITextField. Uh oh, why is the Keyboard covering the UIAlertView? Well there is just a simple fix to this. We just add two more lines of code and it will fix that. Add this to your code

CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60); [alert setTransform:myTransform];


 So now your full code should be looking like this.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Enter Name Here” message:@”this gets covered!” delegate:self cancelButtonTitle:@”Dismiss” otherButtonTitles:@”OK!”, nil]; UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)]; CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60); [alert setTransform:myTransform]; [myTextField setBackgroundColor:[UIColor whiteColor]]; [alert addSubview:myTextField]; [alert show]; [alert release]; [myTextField release];


 Now if you Build and Run, you will notice the UITextField is a little higher and when you tap the UITextField the Keyboard doesn’t cover it up anymore. That is what the CGAffineTransform was for. So that is basically it! There is a video tutorial also available and if you like video tutorial more then written ones you can check it out out by clicking HERE. You can download the source code below. Happy iCoding!

from:http://icodeblog.com/2009/11/09/iphone-coding-tutorial-inserting-a-uitextfield-in-a-uialertview/

 

 

 

 

  • 大小: 66.4 KB
  • 大小: 26.3 KB
分享到:
评论

相关推荐

    iPhone Coding Tutorial – In Application Emailing

    这篇“iPhone Coding Tutorial – In Application Emailing”教程将指导开发者如何在iPhone应用程序中集成电子邮件功能,无需离开应用就能发送邮件。这篇博客文章的链接虽然不可用(已替换为示例文本),但我们可以...

    信息论与编码 Coding Theory: A First Course

    ### 信息论与编码——《Coding Theory: A First Course》 #### 一、基本信息 - **书名**:《Coding Theory: A First Course》 - **出版社**:Cambridge University Press - **页数**:234页 - **出版日期**:2004...

    Coding Games in Python

    Each chapter in Coding Games in Python shows how to construct a complete working game in simple numbered steps. The book teaches how to use freely available resources, such as PyGame Zero and Blender,...

    A Tutorial on Reed-Solomon Coding for Fault-Tolerance in RAID-like Systems

    ### 一、里德-所罗门编码(Reed-Solomon Coding)基础 里德-所罗门编码是一种非二进制线性错误校正码,广泛应用于数据存储和通信系统中,以提供强大的错误检测和纠正能力。它由Irving S. Reed和Gustave Solomon于...

    Coding project in python

    Using fun graphics and easy-to-follow instructions, Coding Projects in Python is a straightforward, visual guide that shows young learners how to build their own computer projects using Python, an ...

    Coding.Projects.in.Python.2017.pdf

    Perfect for kids ages 10 and over who are ready to take a second step after Scratch, Coding Projects in Python teaches kids how to build amazing graphics, fun games, and useful apps. All they need is ...

    Secure Network Coding for a P2P System

    Network coding is a data transmission technique which allows intermediate nodes in a network to re-code data in transit. In contrast to traditional network communication where a node repeats incoming ...

    A First Course In Coding Theory

    Coding theory by oxford press

    cvpr12_tutorial_sparse_coding.ppt

    cvpr12_tutorial_sparse_coding.ppt

    Coding_Games_in_Scratch(英文版)

    《Coding Games in Scratch》是一本面向初学者的编程教材,主要使用Scratch编程语言来教授游戏开发的基础知识。Scratch是由麻省理工学院(MIT)的“终身幼儿园团队”开发的一款图形化编程工具,旨在帮助孩子们学习编程...

    CVPR12 Tutorial on Deep Learning Sparse Coding

    百度的余凯老师在CVPR2012上的Tutorial

    Coding Projects in Scratch

    The simple, logical steps in Coding Projects in Scratch are fully illustrated with fun pixel art and build on the basics of coding, so that kids can have the skills to make whatever kind of project ...

    Network Coding Fundamentals

    Network coding is an elegant and novel technique introduced at the turn of the millennium to improve network throughput and ...A companion issue deals primarily with applications of network coding.

    iPhone in Action: Introduction to Web and SDK Development

    iPhone in Action: Introduction to Web and SDK Development ...A comprehensive tutorial for iPhone programming Web development, the SDK, and hybrid coding Over 60 web, Dashcode, and SDK examples

    Coding Interview In Java

    2 Reverse Words in a String II 19 3 Evaluate Reverse Polish Notation 21 4 Isomorphic Strings 25 5 Word Ladder 27 6 Word Ladder II 29 7 Median of Two Sorted Arrays 33 8 Kth Largest Element in an Array ...

    Information Theory and Statistics A Tutorial

    This tutorial is concerned with applications of information theory concepts in statistics, in the finite alphabet setting. The information measure known as information divergence or Kullback-Leibler ...

Global site tag (gtag.js) - Google Analytics