创建UIButton
// Create a button sized to our art
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, 0.0f, 300.0f, 233.0f);
button.center = CGPointMake(160.0f, 140.0f);
// Set up the button aligment properties
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
// Set the font and color
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
// Hard code carriage returns
// button.titleLabel.font = [UIFont boldSystemFontOfSize:36.0f];
// [button setTitle:@"Word1\nWord2\nWord3" forState: UIControlStateNormal];
// Let label handle carriage returns
button.titleLabel.font = [UIFont boldSystemFontOfSize:36.0f];
[button setTitle:@"Lorem Ipsum Dolor Sit" forState: UIControlStateNormal];
button.titleLabel.textAlignment = UITextAlignmentCenter;
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
// Add action
[button addTarget:self action:@selector(toggleButton:) forControlEvents: UIControlEventTouchUpInside];
创建一个动画
// Load Butterflies
NSMutableArray *bflies = [NSMutableArray array];
UIImage *img;
for (int i = 1; i <= 17; i++) {
NSString *bfname = [NSString stringWithFormat:@"bf_%d.png", i];
if (img = [UIImage imageNamed:bfname]) [bflies addObject:img];
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 80.0f, 80.0f)];
[imageView setAnimationImages:bflies];
[imageView setAnimationDuration:1.2f];
[imageView startAnimating];
imageView.center = button.center;
一个UIButton翻转的例子
@implementation TestBedViewController
- (IBAction) flip: (UIButton *) button
{
// Hide the view that's going away
[self.view viewWithTag:BUTTON1].alpha = 1.0f;
[self.view viewWithTag:BUTTON2].alpha = 1.0f;
[button setAlpha:0.0f];
// Decide which animation to use
UIViewAnimationTransition trans;
trans = (button.tag == BUTTON1) ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight;
// Animate the flip
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationTransition:trans forView:[self.view viewWithTag:CLEARVIEW] cache:YES];
[[self.view viewWithTag:CLEARVIEW] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
}
UISilder的使用
// Create slider
UISlider *slider = [[UISlider alloc] initWithFrame:baseFrame];
slider.center = CGPointMake(160.0f, 140.0f);
slider.value = 0.0f;
// Create the callbacks for touch, move, and release
[slider addTarget:self action:@selector(startDrag:) forControlEvents:UIControlEventTouchDown];
[slider addTarget:self action:@selector(updateThumb:) forControlEvents:UIControlEventValueChanged];
[slider addTarget:self action:@selector(endDrag:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
// Present the slider
[self.view addSubview:slider];
[self performSelector:@selector(updateThumb:) withObject:slider afterDelay:0.1f];
//创建图片的例子
- (UIImage *) createImageWithLevel: (float) aLevel
{
UIGraphicsBeginImageContext(CGSizeMake(40.0f, 100.0f));
CGContextRef context = UIGraphicsGetCurrentContext();
float INSET_AMT = 1.5f;
// Create a filled rect for the thumb
[[UIColor darkGrayColor] setFill];
CGContextAddRect(context, CGRectMake(INSET_AMT, 40.0f + INSET_AMT, 40.0f - 2.0f * INSET_AMT, 20.0f - 2.0f * INSET_AMT));
CGContextFillPath(context);
// Outline the thumb
[[UIColor whiteColor] setStroke];
CGContextSetLineWidth(context, 2.0f);
CGContextAddRect(context, CGRectMake(2.0f * INSET_AMT, 40.0f + 2.0f * INSET_AMT, 40.0f - 4.0f * INSET_AMT, 20.0f - 4.0f * INSET_AMT));
CGContextStrokePath(context);
// Create a filled ellipse for the indicator
[[UIColor colorWithWhite:aLevel alpha:1.0f] setFill];
CGContextAddEllipseInRect(context, CGRectMake(0.0f, 0.0f, 40.0f, 40.0f));
CGContextFillPath(context);
// Label with a number
NSString *numstring = [NSString stringWithFormat:@"%0.1f", aLevel];
UIColor *textColor = (aLevel > 0.5f) ? [UIColor blackColor] : [UIColor whiteColor];
centerText(context, @"Georgia", 20.0f, numstring, CGPointMake(20.0f, 20.0f), textColor);
// Outline the indicator circle
[[UIColor grayColor] setStroke];
CGContextSetLineWidth(context, 3.0f);
CGContextAddEllipseInRect(context, CGRectMake(INSET_AMT, INSET_AMT, 40.0f - 2.0f * INSET_AMT, 40.0f - 2.0f * INSET_AMT));
CGContextStrokePath(context);
// Build and return the image
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
//设置UISlider点击和正常两种状态
// create a new custom thumb image and use it for the highlighted state
UIImage *customimg = [self createImageWithLevel:aSlider.value];
[aSlider setThumbImage: simpleThumbImage forState: UIControlStateNormal];
[aSlider setThumbImage: customimg forState: UIControlStateHighlighted];
previousValue = aSlider.value;
预留
预留
预留
预留
预留
预留
分享到:
相关推荐
WebBrowser控件使用详解,WebBrowser控件使用详解
《Visual Basic.NET 2008控件使用范例详解》作者拥有10年的编程经验,通过近200个范例的典型应用,帮助读者透彻理解Visua1 Basic.NET 2008的控件及其应用。全书共分13章,分别介绍了可调节类控件、选择类控件、显示...
DevExpress是一个比较有名的...本文档主要介绍DevExpress控件使用的详细说明,通过详细说明基本使用方法和属性说明,可以更加快速的入门。总体来讲,使用DevExpress控件,可以获得更高效的界面设计以及更美观的效果。
Fpspread1控件使用手册 对于spread控件各项属性的设置有比较清楚详细的说明
C1控件使用手册,比较全面,中文版的,对于要学习C1控件的童鞋,很适用!
DevExpress是一个比较有名的...本文档主要介绍DevExpress控件使用的详细说明,通过详细说明基本使用方法和属性说明,可以更加快速的入门。总体来讲,使用DevExpress控件,可以获得更高效的界面设计以及更美观的效果。
《Visual C# 2008控件使用范例详解》作者拥有10年的编程经验,通过近200个范例的典型应用,帮助读者透彻理解Visual C#2008的控件及其应用。全书共分13章,分别介绍了可调节类控件、选择类控件、显示类控件、组合类...
MSComm控件使用详解MSComm控件使用详解MSComm控件使用详解MSComm控件使用详解
《Visual C# 2008控件使用范例详解》作者拥有10年的编程经验,通过近200个范例的典型应用,帮助读者透彻理解Visual C#2008的控件及其应用。全书共分13章,分别介绍了可调节类控件、选择类控件、显示类控件、组合类...
《Visual C# 2008控件使用范例详解》完整版本,本资源补齐了网上其他资源所缺少101~150页,并添加了详细书签。 本资源分两卷上传,这是第1卷。访问http://download.csdn.net/user/zgc988可以方便查找第2卷的下载...
C# DataGridView控件使用全攻略
《Visual C# 2008控件使用范例详解》完整版本,本资源补齐了网上其他资源所缺少101~150页,并添加了详细书签。 本资源分两卷上传,这是第2卷。访问http://download.csdn.net/user/zgc988可以方便查找第1卷的下载...
使用VB.NET写的CHART控件使用例程,简单易懂.
TreeView控件使用技巧
Dev里面DataGid控件使用,Dev里面DataGid控件使用
Visual Basic.NET2008控件使用范例详解,有大多数的控件详细介绍和示例代码哦!
MFC常用控件使用
VS C# 介绍 控件 使用 实例 使用大全 范例 例子
很好地控件使用教程,叫你如何使用控件,以及实例演示