/***************************************************************************/
【拉伸 图片】
/***************************************************************************/
/***************************************************************************/
(myString )Hello town -----> Hello world(myNewString )
【分段控件 标题获取】
[mySegment titleForSegmentAtIndex:mySegment.selectedSegmentIndex]; // 通过索引号获取相对应的标题
【LCD 电子时钟字体】
DBLCDTempBlack

arc4random()%12 随机数 范围是 0~11
[self.array count]==12; 数组下标 范围是0~11
【加载 资源图片】
[img setImage:FH_GetWithImage(@"imgName", @"png")]; // 加载图片尽量这样写
[UIImage imageNamed:@"imgName. png"]; // 不要这样写,图片多了就不好了
/***************************************************************************/
【列表 背景】
44*44 大小的图片 设置背景颜色 平铺 就可以做背景图
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"1.png"]]];
/***************************************************************************/
self.tableView.tableHeaderView=self.searchBar; // 搜索栏和列表一起滚动
self.tableView.rowHeight = 60;
【cell 分割线图片】
/***************************************************************************/
【cell 背景颜色】
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds];
cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:47.0/255.0 green:47.0/255.0 blue:47.0/255.0 alpha:1.0];
【pageController 颜色】
[mypagecontrol setCurrenPageIndicatorTintColor:[UIColor redColor]];
[mypagecontrol setPageIndicatorTintColor:[UIColor blackColor]];
/***************************************************************************/
【图像 动画】
UIImageView 对象 属性: 默认是 每 秒 30 帧 播放速度
animationImages 存放图片的数组 (NSArray)
isAnimating 正在以动画方式播放图片 (BOOL)
startAnimating 开始播放动画
stopAnimating 停止播放动画
/***************************************************************************/
- (void)animateIncorrectMessage:(UIView *)view //这个view代表账号和密码的整体
{
CGAffineTransform moveRight = CGAffineTransformTranslate(CGAffineTransformIdentity, 8, 0);CGAffineTransform moveLeft = CGAffineTransformTranslate(CGAffineTransformIdentity, -8, 0);
CGAffineTransform resetTransform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0);
[UIView animateWithDuration:0.1 animations:^{
view.transform = moveLeft;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
view.transform = moveRight;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
view.transform = moveLeft;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
view.transform = moveRight;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
view.transform = resetTransform;
}];
}];
}];
}];
}];
}
/***************************************************************************/
【日期 格式】
创建日期格式对象 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
// MMMM月,d日,yyyy年 hh时,mm分,ss秒,a上下午
字符串 显示当前时间格式 todaysDateString = [dateFormat srtingFromDate:[NSDate date]];
/***************************************************************************/
【两日期相差 多少天】
-(void)calculateDateDifference:(NSDate*)choseDate
{
NSDate *todaysDate = [NSDate date];
NSTimeInterval *difference = [todaysDate timeIntervalSinceDate:chosenDate]/86400;
// 除以一天的秒数得到天数 1天 = 86400秒
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM d ,yyyy hh:mm:ssa"];
todaysDateString = [dateFormat string FromDate:todaysDate];
chosenDateString = [dateFormat string FromDate:chosenDate];
输出:NSString *differenceOutput = [[NSString alloc] initWithFormat:@"Between chosen date (%@) and
today(%@) in days: %1.2f",chosenDateString,todaysDateString,fabs(difference)]; // C方法取绝对值
}
①-(IBAction)setDateTime:(id)sender
{
// (DateChooserViewController ) self.delegate = self (ViewController )
// 选择了日期
②-(void)viewDidAppear:(BOOL)animated
{
// (DateChooserViewController ) self.delegate = self (ViewController )
[(ViewController *)self.delegate calculateDateDifference:[NSDate date]];
// 取消选择了日期,未选择日期。返回当前日期
}
【绘制按钮 普通和高亮】---小图片(15*15)贴大按钮(45*45),不会自动拉伸变形
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
closeButton.frame = CGRectMake(320 - 45.0f,0.0f,45.0f,45.0f);
closeButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
CGRect rect = CGRectMake(0.0f, 0.0f, 45.0f, 45.0f);
UIImage *closeButtonImage = [UIImage imageNamed:@"close.png"];
/***************************************************************************/
// 绘制高亮
原理:获取按钮Size大小的画布并填充FillRect黑色深一点的颜色,
将原图closeButtonImage绘制drawInRect在画布上,保留alpha再截取画布图片(45*45)做高亮图
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0f); // 绘制大小,透明,比例
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:35.0/255.0 green:35.0/255.0 blue:35.0/255.0 alpha:1.0] CGColor]);
CGContextFillRect(context, rect);
[closeButtonImage drawInRect:CGRectMake(15.0f,15.0f,closeButtonImage.size.width,closeButtonImage.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
// 图片是15*15 按钮是 45*45 x,y坐标=(45-15)/2=15.0f
UIImage *highlightedButtonImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); // 绘制结束
[closeButton setBackgroundImage:highlightedButtonImage forState:UIControlStateHighlighted];
/***************************************************************************/
// 绘制普通
原理:获取按钮Size大小的画布,
将原图closeButtonImage绘制drawInRect在画布上,alpha改0.5半透明,再截取画布图片(45*45)做普通图
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0f); // 绘制大小,透明,比例
UIGraphicsGetCurrentContext();
[closeButtonImage drawInRect:CGRectMake(15.0f,15.0f,closeButtonImage.size.width,closeButtonImage.size.height) blendMode:kCGBlendModeNormal alpha:0.5];
// 图片是15*15 按钮是 45*45 x,y坐标=(45-15)/2=15.0f
UIImage *normalButtonImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); // 绘制结束
[closeButton setBackgroundImage:normalButtonImage forState:UIControlStateNormal];
/***************************************************************************/
【改变 pagecontrol样式】
- (void)viewDidLoad
{
[super viewDidLoad];
[self setCurrentPage:self.page.currentPage]; //
一开始调用这个方法就改变pagecontrol样式
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
self.page.currentPage=scrollView.contentOffset.x/320;
[self setCurrentPage:self.page.currentPage]; //
滚动切换 再调用这个方法改变pagecontrol样式
}
- (void) setCurrentPage:(NSInteger)currentPage
{
for (NSInteger indexPage
= 0; indexPage < [page.subviews count];
indexPage++)
{
UIImageView *
subview = [page.subviews objectAtIndex:indexPage];
CGSize size;
size.height = 24/2;
size.width = 24/2;
[subview setFrame:CGRectMake(subview.frame.origin.x,
subview.frame.origin.y,
size.width,size.height)];
if (indexPage == currentPage)
{
[subview setImage:[UIImage imageNamed:@"a.png"]];
}
else
{
[subview setImage:[UIImage imageNamed:@"d.png"]];
}
}
}