>

//添加按钮澳门博发娱乐官网,这里需要加上大括

- 编辑:澳门博发娱乐官网 -

//添加按钮澳门博发娱乐官网,这里需要加上大括

- sw_addUtilityButtonWithColor:(UIColor *)color title:(NSString *)title;- sw_addUtilityButtonWithColor:(UIColor *)color icon:(UIImage *)icon;@end

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d",

[indexPath section], [indexPath row]];//以indexPath来唯一确定cell

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];//出列可重用的cell

if(cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}

****初始化复位****
self.buttonView.transform = CGAffineTransformIdentity;

发现会变灰色,说明在这个状态下没设置我们的皮肤,

}

 //1,初始化 [scrollViewButtonViewRight setFrame:CGRectMake(CGRectGetWidth(self.bounds), 0, [self rightUtilityButtonsWidth], _height)]; //2,添加到滚动视图上 [self.cellScrollView addSubview:scrollViewButtonViewRight]; //3,操作按钮布局与事件回调设置 [scrollViewButtonViewLeft populateUtilityButtons]; [scrollViewButtonViewRight populateUtilityButtons];

if([selfrespondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])

{

//去掉系统默认的偏移

self.automaticallyAdjustsScrollViewInsets=NO;

//获取tabelView的偏移属性

UIEdgeInsetsinsets =self.tableView.contentInset;

//设置tableView的偏移属性值

insets.top=self.navigationController.navigationBar.bounds.size.height;

//设置属性

self.tableView.contentInset=insets;

self.tableView.scrollIndicatorInsets= insets;

}

self.tableView.frame=CGRectMake(0,20,self.view.bounds.size.width,self.view.bounds.size.height);

2.TransForm属性
平移
CGAffineTransform transForm = self.buttonView.transform;
self.buttonView.transform = CGAffineTransformTranslate(transForm, 10, 0);

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];

澳门博发娱乐官网 1

@property (nonatomic, strong) NSArray *utilityButtons;//存放操作按钮的数组@property (nonatomic) CGFloat utilityButtonWidth;//操作按钮的宽度@property (nonatomic, weak) SWTableViewCell *parentCell;//操作按钮所在的cell@property (nonatomic) SEL utilityButtonSelector;//操作按钮点击事件

让UITableView的Cell不重用,解决方案

1.NSString过滤特殊字符串
定义一个特殊字符的集合
NSCharacterSet set = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、[]{}#%-+=|~<>$€•'@#$%&()*+'""];

//此rc为btn在controllerA中的rect

button.titleLabel.font = [UIFont systemFontOfSize:17];

//计算自身的总宽度- getWidth { return KButtonWidthDefault * _buttons.count;}- layoutButtons { NSInteger buttonCount = 1000; for (UIButton *button in _buttons) { button.frame = CGRectMake((buttonCount-1000)*KButtonWidthDefault, 0, KButtonWidthDefault, self.bounds.size.height); button.tag = buttonCount; [button addTarget:_parentCell action:_buttonSelector forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button]; buttonCount++; }}

设置tableView局部刷新

define TOCK NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)

4.Alert提示宏定义

NSString *jsonPath =[[NSBundle mainBundle]pathForResource:jsonName ofType:nil];

self.bottomScrollView.showsHorizontalScrollIndicator = NO;

阅读优秀的开源项目是提高编程能力的有效手段,我们能够从中开拓思维、拓宽视野,学习到很多不同的设计思想以及最佳实践。阅读他人代码很重要,但动手仿写、练习却也是很有必要的,它能进一步加深我们对项目的理解,将这些东西内化为自己的知识和能力。然而真正做起来却很不容易,开源项目阅读起来还是比较困难,需要一些技术基础和耐心。本系列将对一些著名的iOS开源类库进行深入阅读及分析,并仿写这些类库的基本实现,加深我们对底层实现的理解和认识,提升我们iOS开发的编程技能。

设置tableViewcell不让点击等各个属性

import

ABPeoplePickerNavigationControllerDelegate

  • (void)addAddress {
    RYLog(@"选择联系人");
    ABPeoplePickerNavigationController * vc =[[ABPeoplePickerNavigationController alloc] init];
    vc.peoplePickerDelegate =self;
    [selfpresentViewController:vc animated:YEScompletion:nil];
    }

只能在其中设置它的背景图。button和title在它对应的viewController中设置

}

 //滚动视图初始化 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, _height)]; scrollView.contentSize = CGSizeMake(self.bounds.size.width + [rightButtonView getWidth], self.height); scrollView.delegate = self; scrollView.showsHorizontalScrollIndicator = NO; scrollView.scrollsToTop = NO; _cellScrollView = scrollView; [_cellScrollView addSubview:_rightButtonView]; UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, _height)]; contentView.backgroundColor = [UIColor whiteColor]; [_cellScrollView addSubview:contentView]; _cellContentView = contentView; //将原来cell上的内容添加到滚动视图上 UIView *contentViewParent = self; if (![NSStringFromClass([[self.subviews objectAtIndex:0] class]) isEqualToString:kTableViewCellContentView]) { // iOS 7 contentViewParent = [self.subviews objectAtIndex:0]; } NSArray *cellSubviews = [contentViewParent subviews]; [self insertSubview:_cellScrollView atIndex:0]; for (UIView *subview in cellSubviews) { [_cellContentView addSubview:subview]; }}

ScrollView被忘记的牛逼代理方法

过滤字符串的特殊字符
NSString *newString = [NSString stringByTrimmingCharactersInSet:set];

tableView.delaysContentTouches = NO;

@implementation CBSlideView

 UIScrollView *cellScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), _height)]; cellScrollView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds) + [self utilityButtonsPadding], _height); cellScrollView.contentOffset = [self scrollViewContentOffset]; cellScrollView.delegate = self; cellScrollView.showsHorizontalScrollIndicator = NO; cellScrollView.scrollsToTop = NO;

self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;

旋转
CGAffineTransform transForm = self.buttonView.transform;
self.buttonView.transform = CGAffineTransformRotate(transForm, M_PI_4);

self.automaticallyAdjustsScrollViewInsets = NO;

if (btn.tag == pageNum ) {

 UIView *contentViewParent = self; if (![NSStringFromClass([[self.subviews objectAtIndex:0] class]) isEqualToString:kTableViewCellContentView]) { // iOS 7 contentViewParent = [self.subviews objectAtIndex:0]; } NSArray *cellSubviews = [contentViewParent subviews]; [self insertSubview:cellScrollView atIndex:0]; for (UIView *subview in cellSubviews) { [self.scrollViewContentView addSubview:subview]; }

//一个section刷新

NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];

[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];

//一个cell刷新

NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

define TICK CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();

还有在设置backgroundColor时,使用cell设置时左移或者右移颜色是不会变的,而用cell.contentCell设置时,移动后的空白会显示cell的默认颜色,这种情况视实际情况选择。

}

可变数组的扩展,提供了生成指定样式的操作按钮的功能 。NSMutableArray+SWUtilityButtons类提供了两个初始化操作按钮的方法@interface NSMutableArray (SWUtilityButtons)

如何设置Plain 风格下UITableView的Section的HeaderView不在UITableview上浮动

pragma mark -- ABPeoplePickerNavigationControllerDelegate

  • (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
    ABMultiValueRef valuesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFIndex index = ABMultiValueGetIndexForIdentifier(valuesRef,identifier);

//电话号码

CFStringRef telValue = ABMultiValueCopyValueAtIndex(valuesRef,index);
[selfdismissViewControllerAnimated:YEScompletion:^{
self.addressV.telnum.text = (__bridgeNSString *)telValue;

}];

}

37.用WebView加载页面,提前获取页面的高度
可以获得内容高度,但是网络不好时,不准确
1.webView.scrollView.contentSize.height;
获取的高度较为准确
2.[[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] intValue]

UIRectCornerTopRight

}

SWTableViewCell是一个继承自UITableViewCell的自定义Cell,它上面放了一个UIScrollerView,这个滚动视图上放了Cell内容、左侧操作菜单和右侧操作菜单。正常情况下,显示cell内容,当往左侧滑动时,滚动视图往左移动,显示右侧的操作菜单,右滑同理。左、右操作菜单上放置一些操作按钮,由使用者配置,包括按钮的数量,样式,位置等。这些按钮的事件统一回调给使用者,由使用者指定具体实现。

-tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPat{

if([cellrespondsToSelector:@selector(setLayoutMargins:)]) {

[cellsetLayoutMargins:UIEdgeInsetsZero];

}

if([cellrespondsToSelector:@selector(setSeparatorInset:)]){

[cellsetSeparatorInset:UIEdgeInsetsZero];

}}

import

12.PCH文件的建立

_slideView.frame = frame;

滑动cell时,操作菜单栏开始慢慢出现

//先定义一个View作为tableViewFootView【防止直接添加控件超出范围】

UIView* myView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,80)];

myView.backgroundColor= [UIColoryellowColor];

_tableView.tableFooterView= myView;//让myView作为_tableView.tableFooterView

//定义一个控件,现在myView就作为_tableView.tableFooterView了,正常使用,不会在出现控件超出范围问题了

UIButton* btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

btn.backgroundColor= [UIColorredColor];

btn.frame=CGRectMake(0,20,self.view.bounds.size.width,40);

[btnsetTitle:@"点击"forState:UIControlStateNormal];

[btnaddTarget:selfaction:@selectorforControlEvents:UIControlEventTouchUpInside];

[myViewaddSubview:btn];

缩放
self.buttonView.transform = CGAffineTransformScale(transForm, 1.2, 1.2);

//NSLog(@"%@",notiInfo.userInfo);

[_topView  addSubview:self.slideView];

首先创建ZCJButtonView,存放操作按钮,设置这些按钮的回调,主要方法如下:- initWithFrame:frame Buttons:(NSArray *)buttons parentCell:(ZCJTableViewCell *)parentCell buttonSelector:buttonSelector{self = [super initWithFrame:frame];if {_buttons = buttons;_parentCell = parentCell;_buttonSelector = buttonSelector;}return self;}

判断tableView向上滑还是向下滑 笨方法方法

define Alert(S, …) [[[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:(S), ##VA_ARGS] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show]

5.让iOS应用直接退出

  • (void)exitApplication {
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    UIWindow *window = app.window;
    [UIView animateWithDuration:1.0f animations:^{
    window.alpha = 0;
    } completion:^(BOOL finished) {
    exit(0);
    }];
    }

6.快速求总和 最大值 最小值 和 平均值
NSArray 快速求总和 最大值 最小值 和 平均值
NSArray *array = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0", @"10", nil];
CGFloat sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue];
CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
CGFloat max =[[array valueForKeyPath:@"@max.floatValue"] floatValue];
CGFloat min =[[array valueForKeyPath:@"@min.floatValue"] floatValue];
NSLog(@"%fn%fn%fn%f",sum,avg,max,min);

7.修改Label中不同文字颜色

  • (void)touchesEnded:(NSSet<UITouch> *)touches withEvent:(UIEvent *)event
    {
    [self editStringColor:self.label.text editStr:@"好" color:[UIColor blueColor]];
    }

  • (void)editStringColor:(NSString *)string editStr:(NSString *)editStr color:(UIColor *)color {
    // string为整体字符串, editStr为需要修改的字符串
    NSRange range = [string rangeOfString:editStr];

    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:string];

    // 设置属性修改字体颜色UIColor与大小UIFont
    [attribute addAttributes:@{NSForegroundColorAttributeName:color} range:range];

    self.label.attributedText = attribute;
    }

8.Label行间距
-(void)test{
NSMutableAttributedString *attributedString =
[[NSMutableAttributedString alloc] initWithString:self.contentLabel.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:3];

//调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName
                         value:paragraphStyle
                         range:NSMakeRange(0, [self.contentLabel.text length])];
self.contentLabel.attributedText = attributedString;

}

9.UIImageView填充模式
@"UIViewContentModeScaleToFill", // 拉伸自适应填满整个视图
@"UIViewContentModeScaleAspectFit", // 自适应比例大小显示
@"UIViewContentModeScaleAspectFill", // 原始大小显示
@"UIViewContentModeRedraw", // 尺寸改变时重绘
@"UIViewContentModeCenter", // 中间
@"UIViewContentModeTop", // 顶部
@"UIViewContentModeBottom", // 底部
@"UIViewContentModeLeft", // 中间贴左
@"UIViewContentModeRight", // 中间贴右
@"UIViewContentModeTopLeft", // 贴左上
@"UIViewContentModeTopRight", // 贴右上
@"UIViewContentModeBottomLeft", // 贴左下
@"UIViewContentModeBottomRight", // 贴右下

10.iOS开发中一些相关的路径
//模拟器的位置:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs

//文档安装位置:
/Applications/Xcode.app/Contents/Developer/Documentation/DocSets

//插件保存路径:
~/Library/ApplicationSupport/Developer/Shared/Xcode/Plug-ins

//自定义代码段的保存路径:
~/Library/Developer/Xcode/UserData/CodeSnippets/
//如果找不到CodeSnippets文件夹,可以自己新建一个CodeSnippets文件夹。

//证书路径
~/Library/MobileDevice/Provisioning Profiles

//获取 iOS 路径的方法
//获取家目录路径的函数
NSString *homeDir = NSHomeDirectory();

//获取Documents目录路径的方法
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];

//获取Documents目录路径的方法
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];

//获取tmp目录路径的方法:
NSString *tmpDir = NSTemporaryDirectory();

11.关于隐藏Navigation bar
/*
//设置滑动的时候隐藏Navigation bar
navigationController.hidesBarsOnSwipe = Yes
//动态隐藏NavigationBar
*/

1当我们的手离开屏幕时候隐藏

  • (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
    {
    if(velocity.y > 0)
    {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    } else {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
    }
    PS: velocity.y这个量,在上滑和下滑时,变化极小(小数),但是因为方向不同,有正负之分,这就很好处理了

2.在滑动过程中隐藏
(1) self.navigationController.hidesBarsOnSwipe = YES;
(2) 滑动试图的代理方法

  • (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
    CGFloat offsetY = scrollView.contentOffset.y + __tableView.contentInset.top;
    CGFloat panTranslationY = [scrollView.panGestureRecognizer translationInView:self.tableView].y;
    if (offsetY > 64) {
    if (panTranslationY > 0)
    {
    //下滑趋势,显示
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    } else {
    //上滑趋势,隐藏
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    }
    } else {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
    }
    PS: 这里的offsetY > 64只是为了在视图滑过navigationBar的高度之后才开始处理,防止影响展示效果。panTranslationY是scrollView的pan手势的手指位置的y值,可能不是太好,因为panTranslationY这个值在较小幅度上下滑动时,可能都为正或都为负,这就使得这一方式不太灵敏.

12.自动处理键盘事件,实现输入框防遮挡的插件
https://github.com/hackiftekhar/IQKeyboardManager

13.设置字体和行间距
1 设置字体和行间距
UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake(50, 100, 300, 200)];
lable.text = @"大家好,我是奋拓达,在这里我们一起学习新的知识,总结我们遇到的那些坑,共同的学习,共同的进步,共同的努力,只为美好的明天!!!有问题一起相互的探讨—123456!!!";
lable.numberOfLines = 0;
lable.font = [UIFont systemFontOfSize:12];
lable.backgroundColor = [UIColor grayColor];
[self.view addSubview:lable];

2 设置每个字体之间的间距
NSKernAttributeName 这个对象所对应的值是一个NSNumber对象(包含小数),作用是修改默认字体之间的距离调整,值为0的话表示字距调整是禁用的; NSMutableAttributedString * str = [[NSMutableAttributedString alloc]initWithString:lable.text attributes:@{NSKernAttributeName:@(5.0)}];

3 设置某写字体的颜色
NSForegroundColorAttributeName 设置字体颜色
NSRange blueRange = NSMakeRange([[str string] rangeOfString:@"xiao公子"].location, [[str string] rangeOfString:@"Frank_chun"].length);
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:blueRange];
NSRange blueRange1 = NSMakeRange([[str string] rangeOfString:@"123456"].location, [[str string] rangeOfString:@"438637472"].length);
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:blueRange1];

****4 设置每行之间的间距****
NSParagraphStyleAttributeName 设置段落的样式
NSMutableParagraphStyle * par = [[NSMutableParagraphStyle alloc]init];
[par setLineSpacing:20];

*****5 为某一范围内文字添加某个属性*****
NSMakeRange表示所要的范围,从0到整个文本的长度
[str addAttribute:NSParagraphStyleAttributeName value:par range:NSMakeRange(0, lable.text.length)]; [lable setAttributedText:str];

14.点击button倒计时
1第一种方法
// 点击button倒计时

self.scrollView.bounces = NO;

[_topView addSubview:view];

快速滑动cell时完成显示操作菜单栏。当只少量滑动时,恢复到cell正常状态- scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:velocity targetContentOffset:(inout CGPoint *)targetContentOffset {switch {case ZCJCellStateCenter:if (velocity.x >= 0.5) {[self scrollToRight:targetContentOffset];}else {if (targetContentOffset->x >= [self.rightButtonView getWidth] / 2) {[self scrollToRight:targetContentOffset];}else {[self scrollToCenter:targetContentOffset];}}break;

}

3.计算方法耗时时间间隔
获取时间间隔

//有些时候我们想让UIButton的title居左对齐,我们设置

lineView.backgroundColor = UIColorRGBA(239, 93, 58, 1);

SWTableViewCell是UITableViewCell的子类,它具有左右滑动显示操作菜单的功能。很多APP都有这个功能,比如微信列表页往左侧滑动显示操作菜单,可以删除或标为未读。我们看一下它的效果:

处理tableView.tableFooterView添加控件问题点击无效等

import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong) UIButton * timeButton;
@property (nonatomic, strong) NSTimer * timer;
@property (nonatomic, strong)UIButton * btn;
@end@implementation ViewController
{
NSInteger _time;
}

  • (void)viewDidLoad {
    [super viewDidLoad];
    _time = 5;
    self.btn = [UIButton buttonWithType:UIButtonTypeCustom]; _btn.backgroundColor = [UIColor orangeColor];
    [_btn setTitle:@"获取验证码" forState:UIControlStateNormal]; _btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_timeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self refreshButtonWidth];
    [self.view addSubview:self.btn];
    }
  • (void)refreshButtonWidth{
    CGFloat width = 0;
    if (_btn.enabled){
    width = 100;
    } else {
    width = 200;
    }
    _btn.center = CGPointMake(self.view.frame.size.width/2, 200);
    _btn.bounds = CGRectMake(0, 0, width, 40);
    //每次刷新,保证区域正确
    [_btn setBackgroundImage:[self imageWithColor:[UIColor orangeColor] andSize:_btn.frame.size] forState:UIControlStateNormal];
    [_btn setBackgroundImage:[self imageWithColor:[UIColor lightGrayColor] andSize:_btn.frame.size] forState:UIControlStateDisabled];
    }
  • (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)aSize{
    CGRect rect = CGRectMake(0.0f, 0.0f, aSize.width, aSize.height); UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
    return image;
    }
  • (void)btnAction:(UIButton *)sender{
    sender.enabled = NO;
    [self refreshButtonWidth];
    [sender setTitle:[NSString stringWithFormat:@"获取验证码(%zi)", _time] forState:UIControlStateNormal];
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timeDown) userInfo:nil repeats:YES];
    }
  • (void)timeDown{
    _time —;
    if (_time == 0) {
    [_btn setTitle:@"重新获取" forState:UIControlStateNormal]; _btn.enabled = YES;
    [self refreshButtonWidth];
    [_timer invalidate];
    _timer = nil;
    _time = 5 ;
    return;
    }
    [_btn setTitle:[NSString stringWithFormat:@"获取验证码(%zi)", _time] forState:UIControlStateNormal];
    }

2 第二种方法
// 点击发送验证码

  • (void)sendMessage:(UIButton )btn{
    if (self.phoneField.text.length == 0) {
    [self remindMessage:@"请输入正确的手机号"];
    }else{
    __block int timeout=60;
    //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue); dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0
    NSEC_PER_SEC, 0);
    //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
    if(timeout<=0){
    //倒计时结束,关闭
    dispatch_source_cancel(_timer); dispatch_async(dispatch_get_main_queue(), ^{
    // 设置界面的按钮显示 根据自己需求设置
    [btn setTitle:@"发送验证码" forState:UIControlStateNormal]; btn.userInteractionEnabled = YES;
    });
    }else{
    int seconds = timeout % 60;
    NSString *strTime = [NSString stringWithFormat:@"%d", seconds];
    if ([strTime isEqualToString:@"0"]) {
    strTime = [NSString stringWithFormat:@"%d",60];
    }
    dispatch_async(dispatch_get_main_queue(), ^{
    //设置界面的按钮显示 根据自己需求设置
    //NSLog(@"____%@",strTime);
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [btn setTitle:[NSString stringWithFormat:@"%@秒后重新发送",strTime] forState:UIControlStateNormal];
    [UIView commitAnimations];
    btn.userInteractionEnabled = NO;
    });
    timeout—;
    }
    });
    dispatch_resume(_timer);
    }

15.修改textFieldplaceholder字体颜色和大小
textField.placeholder = @"username is in here!"; [/p][textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

16.图片拉伸
UIImage* img=[UIImage imageNamed:@"2.png"];//原图
UIEdgeInsets edge=UIEdgeInsetsMake(0, 10, 0,10);
UIImageResizingModeStretch:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片
UIImageResizingModeTile:平铺模式,通过重复显示UIEdgeInsets指定的矩形区域来填充图
img= [img resizableImageWithCapInsets:edge resizingMode:UIImageResizingModeStretch];
self.imageView.image=img;

17.去掉导航栏下边的黑线
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

18.修改pagecontrol颜色
_pageControl.currentPageIndicatorTintColor=SFQRedColor;
_pageControl.pageIndicatorTintColor=SFQGrayColor;

19.去掉UITableView的section的粘性,使其不会悬停
//有时候使用UITableView所实现的列表,会使用到section,但是又不希望它粘在最顶上而是跟随滚动而消失或者出现

  • (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == _tableView) {
    CGFloat sectionHeaderHeight = 36;
    if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
    scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
    scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
    }
    }

20.UIImage与字符串互转
1 图片转字符串
-(NSString *)UIImageToBase64Str:(UIImage *) image
{
NSData *data = UIImageJPEGRepresentation(image, 1.0f);
NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
return encodedImageStr;
}

2 字符串转图片
-(UIImage *)Base64StrToUIImage:(NSString *)_encodedImageStr
{
NSData *_decodedImageData = [[NSData alloc] initWithBase64Encoding:_encodedImageStr];
UIImage *_decodedImage = [UIImage imageWithData:_decodedImageData];
return _decodedImage;
}

21.判断NSString中是否包含中文
-(BOOL)isChinese:(NSString *)str{
NSString *match=@"(^[u4e00-u9fa5]+$)";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];
return [predicate evaluateWithObject:str];
}

22.NSDate与NSString的相互转化
-(NSString *)dateToString:(NSDate *)date {
// 初始化时间格式控制器
NSDateFormatter *matter = [[NSDateFormatter alloc] init];
// 设置设计格式
[matter setDateFormat:@"yyyy-MM-dd hh:mm:ss zzz"];
// 进行转换
NSString *dateStr = [matter stringFromDate:date];
return dateStr;
}
-(NSDate *)stringToDate:(NSString *)dateStr {

    // 初始化时间格式控制器
    NSDateFormatter *matter = [[NSDateFormatter alloc] init];
    // 设置设计格式
    [matter setDateFormat:@"yyyy-MM-dd hh:mm:ss zzz"];
    // 进行转换
    NSDate *date = [matter dateFromString:dateStr];
    return date;
}

23.控件的局部圆角
CGRect rect = CGRectMake(0, 0, 100, 50);
CGSize radio = CGSizeMake(5, 5);//圆角尺寸
UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//这只圆角位置
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//创建shapelayer
masklayer.frame = button.bounds;
masklayer.path = path.CGPath;//设置路径
button.layer.mask = mask layer;

24.NavigationBar的透明问题
(1) 如果仅仅是想要navigationBar透明,按钮和标题都在可以使用以下方法:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];//给navigationBar设置一个空的背景图片即可实现透明,而且标题按钮都在

PS: 如果仅仅把navigationBar的alpha设为0的话,那就相当于把navigationBar给隐藏了,大家都知道,父视图的alpha设置为0的话,那么子视图全都会透明的。那么相应的navigationBar的标题和左右两个按钮都会消失。这样显然达不到我们要求的效果。

(2)如果你想在透明的基础上实现根据下拉距离,由透明变得不透明的效果,那么上面那个就显得力不从心了,这就需要我们采用另外一种方法了
//Navigation Bar是一个复合视图,它是有许多个控件组成的,那么我们就可以从他的内部入手
[[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 0;//这里可以根据scrollView的偏移量来设置alpha就实现了渐变透明的效果

25.全局设置Navigation Bar标题的样式和barItem的标题样式
//UIColorWithHexRGB( )这个方法是自己定义的,这里只需要给个颜色就好了
[[UINavigationBar appearance] setBarTintColor:UIColorWithHexRGB(0xfefefe)];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:UIColorWithHexRGB(0xfe6d27)}];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:10],NSForegroundColorAttributeName : UIColorWithHexRGB(0x666666)} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize];

26.侧滑手势返回
iOS的侧滑返回手势有着很好的操作体验,不支持侧滑返回的应用绝对不是好应用。但是在开发过程中在自定义了返回按钮,或者某些webView,tableView等页面,侧滑返回手势失效,这时候就需要我们来进行设置一下了,可以在基类里面协商如下代码:

if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//需要遵循一下手势的代理 self.navigationController.interactivePopGestureRecognizer.delegate = self;
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}

问题:当返回navigationController的最顶层的Controller的时候。再次侧滑,这个时候你在点击一个push页面的操作,你会发现卡那了,半天才会有反应。
解释 :这是由于,在最顶层Controller手势依然有效,但是滑动后,并找不到返回的页面。造成软件卡顿,假死所以就要在rootViewController中让此手势失效。把下面的设为NO
self.navigationController.interactivePopGestureRecognizer.enabled = YES;

PS :当然你也可以使用一个第三方库,写的相当棒。他对系统的侧滑返回手势进行拓展,不用从边缘滑动,只要右滑即可返回。最重要的是,他只需要加入项目中即可,不需要一行代码即可实现。附上github 网址
https://github.com/forkingdog/FDFullscreenPopGesture

27.给webView添加头视图
webView是一个复合视图,里面包含有一个scrollView,scrollView里面是一个UIWebBrowserView(负责显示WebView的内容)
UIView webBrowserView = self.webView.scrollView.subviews[0];//拿到webView的webBrowserView
self.backHeadImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenWidth
2/3.0)];
[_backHeadImageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrl] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
[self.webView insertSubview:_backHeadImageView belowSubview:self.webView.scrollView];
//把backHeadImageView插入到webView的scrollView下面
CGRect frame = self.webBrowserView.frame;
frame.origin.y = CGRectGetMaxY(_backHeadImageView.frame);
self.webBrowserView.frame = frame;
//更改webBrowserView的frame向下移backHeadImageView的高度,使其可见

28.模态跳转的动画设置 Model
DetailViewController *detailVC = [[DetailViewController alloc]init];

UIModalTransitionStyleFlipHorizontal  翻转
UIModalTransitionStyleCoverVertical   底部滑出
UIModalTransitionStyleCrossDissolve  渐显
UIModalTransitionStylePartialCurl        翻页

detailVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:detailVC animated:YES completion:nil];

29.图片处理只拿到图片的一部分
UIImage *image = [UIImage imageNamed:filename];
CGImageRef imageRef = image.CGImage;
CGRect rect = CGRectMake(origin.x, origin.y ,size.width, size.height);
//这里的宽高是相对于图片的真实大小
//比如你的图片是400x400的那么(0,0,400,400)就是图片的全尺寸,想取哪一部分就设置相应坐标即可
CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect);
UIImage *imageRect = [[UIImage alloc] initWithCGImage:imageRefRect];

30.给UIView设置图片
UIImage *image = [UIImage imageNamed:@"playing"];
_layerView.layer.contents = (__bridge id)image.CGImage;
_layerView.layer.contentsCenter = CGRectMake(0.25, 0.25, 0.5, 0.5);
//同样可以设置显示的图片范围
//不过此处略有不同,这里的四个值均为0-1之间;对应的依然是写x,y,widt,height

31.给TableView或者CollectionView的cell添加简单动画 (只要在willDisplayCell方法中对将要显示的cell做动画即可)

  • (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array = tableView.indexPathsForVisibleRows;
    NSIndexPath *firstIndexPath = array[0];
    //设置anchorPoint
    cell.layer.anchorPoint = CGPointMake(0, 0.5);
    //为了防止cell视图移动,重新把cell放回原来的位置
    cell.layer.position = CGPointMake(0, cell.layer.position.y);
    //设置cell 按照z轴旋转90度,注意是弧度
    if (firstIndexPath.row < indexPath.row) {
    cell.layer.transform = CATransform3DMakeRotation(M_PI_2, 0, 0, 1.0);
    }else{
    cell.layer.transform = CATransform3DMakeRotation(- M_PI_2, 0, 0, 1.0);
    }
    cell.alpha = 0.0;
    [UIView animateWithDuration:1 animations:^{
    cell.layer.transform = CATransform3DIdentity;
    cell.alpha = 1.0;
    }];
    }

32.两点之间的距离 & 线程中更新UILabel的text
1 两点之间的距离
static__inline__ CGFloat CGPointDistanceBetweenTwoPoints(CGPoint point1, CGPoint point2) {
CGFloat dx = point2.x - point1.x; CGFloat dy = point2.y - point1.y;
returnsqrt(dxdx + dydy);

}

2 线程中更新UILabel的text

abel1为UILabel,当在子线程中,需要进行text的更新的时候,可以使用这个方法来更新。
其他的UIView也都是一样的。
[self.label1 performSelectorOnMainThread:@selector(setText:) withObject:textDisplay waitUntilDone:YES];

33.获得当前硬盘空间
NSFileManagerfm = [NSFileManagerdefaultManager];
NSDictionary
fattributes = [fmattributesOfFileSystemForPath:NSHomeDirectory()error:nil];
NSLog(@"容量%lldG",[[fattributesobjectForKey:NSFileSystemSize]longLongValue]/1000000000);
NSLog(@"可用%lldG",[[fattributesobjectForKey:NSFileSystemFreeSize]longLongValue]/1000000000);

34.ActivityViewController使用AirDrop分享
使用AirDrop进行分享:
NSArray array =@[@"test1",@"test2"];
UIActivityViewController
activityVC = [[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];
[selfpresentViewController:activityVCanimated:YES
completion:^{
NSLog(@"Air");

}];

35.保存全屏为image
CGSizeimageSize = [[UIScreenmainScreen]bounds].size;
UIGraphicsBeginImageContextWithOptions(imageSize,NO,0);
CGContextRefcontext =UIGraphicsGetCurrentContext();
for(UIWindow* windowin[[UIApplicationsharedApplication]windows]) {
if(![windowrespondsToSelector:@selector(screen)] || [windowscreen] == [UIScreenmainScreen]) {
CGContextSaveGState(context);
CGContextTranslateCTM(context, [windowcenter].x, [windowcenter].y);
CGContextConcatCTM(context, [windowtransform]);
CGContextTranslateCTM ( context, -[windowbounds].size.width *[[windowlayer]anchorPoint].x, -[windowbounds].size.height [[windowlayer]anchorPoint].y);
[[windowlayer]renderInContext:context];
CGContextRestoreGState(context);
}
}
UIImage
image = UIGraphicsGetImageFromCurrentImageContext();

36.获取通讯录联系人的电话号码

解决方法:

[self addSubview:self.topView];

操作按钮的点击事件传递到cell上进行处理- buttonAction:sender {UIButton *btn = sender;NSInteger index = btn.tag - 1000;if ([self.delegate respondsToSelector:@selector(swippableTableViewCell:didTriggerRightButtonViewWithIndex:)]) {[self.delegate swippableTableViewCell:self didTriggerRightButtonViewWithIndex:index];}}仿写的ZCJTableViewCell源码在这里:

//加载scrollView和滑动都会执行此方法

- scrollViewDidScroll:(UIScrollView*)scrollView

{

//******判断向上滑动还是向下滑动******

int_lastPosition =0;

intcurrentPostion = scrollView.contentOffset.y;

if(currentPostion - _lastPosition >50) {

_lastPosition = currentPostion;

[UIViewanimateWithDuration:0.2animations:^{

//NSLog;

self.menu.hidden=NO;

_headView.frame=CGRectMake(_headRect.origin.x,_headRect.origin.y-(_headRect.size.height-40),deviceWidth,_headRect.size.height);

_scrollView.frame=CGRectMake(0,_scrollViewRect.origin.y-(_headRect.size.height-40),deviceWidth,_scrollViewRect.size.height+200);

}];

}

elseif(_lastPosition - currentPostion >35)

{

_lastPosition = currentPostion;

[UIViewanimateWithDuration:0.2animations:^{

self.menu.hidden=YES;

// //NSLog;

_headView.frame=_headRect;

_scrollView.frame=_scrollViewRect;

}];}}}

int colomNumber = textView.contentSize.height/size.height;

}else{

其中utilityButtonWidth表示操作按钮的宽度,默认是90。当操作菜单有过多的按钮时,该值将重新计算取均分值,避免按钮太多撑满整个cell。 utilityButtonSelector是操作按钮的点击事件,该事件不在SWUtilityButtonView处理,而是要传递到parentCell中,即操作按钮的点击事件传递到上层cell中。parentCell还有个作用,取得cell的高度给SWUtilityButtonView。计算每个操作按钮的实际宽度- calculateUtilityButtonWidth {CGFloat buttonWidth = kUtilityButtonWidthDefault;if (buttonWidth * _utilityButtons.count > kUtilityButtonsWidthMax) {CGFloat buffer = (buttonWidth * _utilityButtons.count) - kUtilityButtonsWidthMax;buttonWidth -= (buffer / _utilityButtons.count);}return buttonWidth;}操作按钮在页面上布局,以及配置事件响应方,通过tag属性标识每个按钮- populateUtilityButtons {NSUInteger utilityButtonsCounter = 0;for (UIButton *utilityButton in _utilityButtons) {CGFloat utilityButtonXCord = 0;if (utilityButtonsCounter >= 1) utilityButtonXCord = _utilityButtonWidth * utilityButtonsCounter;[utilityButton setFrame:CGRectMake(utilityButtonXCord, 0, _utilityButtonWidth, CGRectGetHeight(self.bounds))];[utilityButton setTag:utilityButtonsCounter];[utilityButton addTarget:_parentCell action:_utilityButtonSelector forControlEvents:UIControlEventTouchDown];[self addSubview: utilityButton];utilityButtonsCounter++;}}

重写scrollView最上方的偏移量

[btn setBackgroundImage:(UIImage*)forState:UIControlStateSelected|UIControlStateHighlighted];

@end

-scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.contentOffset.x > 0) { self.rightButtonView.frame = CGRectMake(scrollView.contentOffset.x + self.bounds.size.width - [self.rightButtonView getWidth], 0, [self.rightButtonView getWidth], _height); }}

-scrollViewWillEndDragging:(UIScrollView*)scrollView withVelocity:velocity targetContentOffset:(inoutCGPoint*)targetContentOffset

{//用来判断,scrollView是上滑还是下滑

NSLog(@"yyyy == %f +++ xxxx == %f",velocity.y,velocity.x);

//记录ScrollView最上方的坐标

NSLog(@"targetContentOffsetyyyy == %f +++ targetContentOffsetxxxx == %f",targetContentOffset->y,targetContentOffset->x);

//根据值处理navigationBar

if(velocity.y>0)

{

self.navigationController.navigationBar.hidden=YES;

}

else

{

self.navigationController.navigationBar.hidden=NO;

}

31.BOOL和bool的区别

self.bottomScrollView.directionalLockEnabled = YES;

SWTableViewCell是一个很棒的自定义cell,它的实现给我们很多启发,在我们日常编写自定义view中有很多可以学习的地方,比如SEL事件往上层传递,scrollView的使用。阅读这个类库的实现方式也让我受益匪浅,我也会在今后继续用这种方式阅读和仿写其它的著名类库,希望大家多多支持。文章中难免有错误有不足,希望大家多多指正。

设置UITableView的滚动条颜色

//或当已知btn时:

UIViewController * vc = _vcArray[i][key] ;

将原来cell上的内容添加到滚动视图上

点击cell单元格的时候取消选中单元格

7.更改UISearchBar的cancel按钮显示文本。

[self.bottomScrollView addSubview:vc.view];

左右两侧的操作菜单类,管理操作按钮的布局、事件回调。在SWUtilityButtonView类中,有以下属性

CGFloat dummyViewHeight =40;

UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.tableView.bounds.size.width, dummyViewHeight)];

self.tableView.tableHeaderView = dummyView;

self.tableView.contentInset = UIEdgeInsetsMake(-dummyViewHeight,0,0,0);

}

NSString * key = [self.vcArray[i] allKeys][0];

滑动显示菜单cell,它统一管理操作菜单的生成、事件处理、响应回调等。cell上的滚动视图的初始化,它的contentSize是左侧操作菜单的加cell的宽度加右侧操作菜单的宽度

cell.selectedBackgroundView= [[UIViewalloc] initWithFrame:cell.frame];cell.selectedBackgroundView.backgroundColor= [UIColorwhiteColor];

-(UIStatusBarStyle)preferredStatusBarStyle;

//添加按钮

当左右滑动cell时,实际上是根据滑动范围控制显示相应左右侧操作菜单- scrollViewDidScroll:(UIScrollView *)scrollView {if (scrollView.contentOffset.x > [self leftUtilityButtonsWidth]) {// 显示右侧操作菜单self.scrollViewButtonViewRight.frame = CGRectMake(scrollView.contentOffset.x + (CGRectGetWidth(self.bounds) - [self rightUtilityButtonsWidth]), 0.0f, [self rightUtilityButtonsWidth], _height);} else {// 显示左侧操作菜单self.scrollViewButtonViewLeft.frame = CGRectMake(scrollView.contentOffset.x, 0.0f, [self leftUtilityButtonsWidth], _height);}}根据用户滑动的力度,显示相应的操作菜单。如果用户滑动范围不足操作菜单宽度的一半,cell回到正常状态,超过时,则滑动到相应的操作菜单- scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:velocity targetContentOffset:(inout CGPoint *)targetContentOffset {switch (_cellState) {case kCellStateCenter:if (velocity.x >= 0.5f) {//滑动力度[self scrollToRight:targetContentOffset];} else if (velocity.x <= -0.5f) {[self scrollToLeft:targetContentOffset];} else {CGFloat rightThreshold = [self utilityButtonsPadding] - ([self rightUtilityButtonsWidth] / 2);CGFloat leftThreshold = [self leftUtilityButtonsWidth] / 2;if (targetContentOffset->x > rightThreshold)//滑动范围超过操作菜单宽度的一半,显示操作菜单栏[self scrollToRight:targetContentOffset];else if (targetContentOffset->x < leftThreshold)[self scrollToLeft:targetContentOffset];else[self scrollToCenter:targetContentOffset];}break;case kCellStateLeft:if (velocity.x >= 0.5f) {[self scrollToCenter:targetContentOffset];} else if (velocity.x <= -0.5f) {// No-op} else {if (targetContentOffset->x >= ([self utilityButtonsPadding] - [self rightUtilityButtonsWidth] / 2))[self scrollToRight:targetContentOffset];else if (targetContentOffset->x > [self leftUtilityButtonsWidth] / 2)[self scrollToCenter:targetContentOffset];else[self scrollToLeft:targetContentOffset];}break;case kCellStateRight:if (velocity.x >= 0.5f) {// No-op} else if (velocity.x <= -0.5f) {[self scrollToCenter:targetContentOffset];} else {if (targetContentOffset->x <= [self leftUtilityButtonsWidth] / 2)[self scrollToLeft:targetContentOffset];else if (targetContentOffset->x < ([self utilityButtonsPadding] - [self rightUtilityButtonsWidth] / 2))[self scrollToCenter:targetContentOffset];else[self scrollToRight:targetContentOffset];}break;default:break;}}操作按钮的响应事件传递到cell中,通过tag判断当前点击的按钮。- rightUtilityButtonHandler:sender {UIButton *utilityButton = (UIButton *)sender;NSInteger utilityButtonTag = [utilityButton tag];if ([_delegate respondsToSelector:@selector(swippableTableViewCell:didTriggerRightUtilityButtonWithIndex:)]) {[_delegate swippableTableViewCell:self didTriggerRightUtilityButtonWithIndex:utilityButtonTag];}}整个类库的实现过程大致就是这些,基本实现思路就是在scrollView上滑动显示菜单区。下面我们自己仿写一下这个类库,以加深我们对它内部实现的理解和掌握。为了简单起见,我们只实现基本的功能,一些细节都忽略掉了。

-tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; }

btn.titleLabel.font =[UIFont systemFontOfSize: 14.0];

- (instancetype)initWithFrame:(CGRect)frame WithViewControllers:(NSArray *)viewControllers{

其实很简单- sw_addUtilityButtonWithColor:(UIColor *)color title:(NSString *)title {UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];button.backgroundColor = color;[button setTitle:title forState:UIControlStateNormal];[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];[self addObject:button];}需要注意的是SWUtilityButtonView初始化和调用过程有一定的顺序,不能搞反了。

DBEmptyTableViewCell* emtyCell = (DBEmptyTableViewCell*)[DBEmptyTableViewCellcellWithTableViewNib:tableView];

emtyCell.message.text=@"还没有动态哦";

//设置其不能被点击

emtyCell.userInteractionEnabled=NO;

//设置其没有点击效果

emtyCell.selectionStyle=UITableViewCellSelectionStyleNone;

returnemtyCell;

2、设置tableView没有线条

tableView.separatorStyle=UITableViewCellSeparatorStyleNone;

2、设置tableView某一个cell没有线条

btncell.separatorInset=UIEdgeInsetsMake(0,0,0, cell.bounds.size.width);

3、设置cell的线条显示完整

-viewDidLayoutSubviews {

if([_tableViewOnerespondsToSelector:@selector(setSeparatorInset:)]) {

[_tableViewOnesetSeparatorInset:UIEdgeInsetsZero];

}

if([_tableViewOnerespondsToSelector:@selector(setLayoutMargins:)]) {

[_tableViewOnesetLayoutMargins:UIEdgeInsetsZero];

}

}

3、设置cell的线条显示完整方案2

cell?.separatorInset =UIEdgeInsetsZero

cell?.layoutMargins =UIEdgeInsetsZero

cell?.preservesSuperviewLayoutMargins =false

_isInside =[_myView pointInside:currentPoint withEvent:event];

[btn setTitleColor:UIColorRGBA(239, 93, 58, 1) forState:UIControlStateNormal];

澳门博发娱乐官网 2SWTableViewCell的地址是:

代理方法:当tableViewcell画出屏幕时,调用此代理方法

CGPoint currentPoint =[touch locationInView:self];

NSString * buttonTitle =  [self.vcArray[i] allKeys][0];

 case ZCJCellStateRight: if (velocity.x >= 0.5) { } else if (velocity.x <= -0.5) { [self scrollToCenter:targetContentOffset]; } else { if (targetContentOffset->x <= [self.rightButtonView getWidth] / 2) { [self scrollToCenter:targetContentOffset]; } else { [self scrollToRight:targetContentOffset]; } } break; default: break; }}

修改tableViewCell选中状态的颜色

//[btn setFont:[UIFont systemFontSize: 14.0]];//这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法

@property (nonatomic,strong) UIScrollView * topScrollView;

NSMutableArray+ZCJButtons类,我们只写一个初始化操作按钮的方法- addButtonWithBackgroundColor:(UIColor *)color withTitle:(NSString *)title {UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];[btn setTitle:title forState:UIControlStateNormal];[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];[btn setBackgroundColor:color];[self addObject:btn];}ZCJTableViewCell简化了很多功能,这里只处理了右侧滑动,类的初始化方法如下- initializar {//右侧操作视图初始化ZCJButtonView *rightButtonView = [[ZCJButtonView alloc] initWithButtons:_rightButtons parentCell:self buttonSelector:@selector(buttonAction:)];rightButtonView.frame = CGRectMake(self.bounds.size.width, 0, [_rightButtonView getWidth], _height);[rightButtonView layoutButtons];_rightButtonView = rightButtonView;

24.DrawRect的注意事项:

// 按钮宽度

NSString *str = textView.text;

self.bottomScrollView.bounces = NO;

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

}

UIRectCornerBottomRight

@property (nonatomic,strong) NSMutableArray * btnArray;

//增益Cell高度减去一行文字的高度

CGFloat buttonWight = kWindowWidth / _vcArray.count;

UIButton *cancalBtn =(UIButton *)searchBtn;

[_topView addSubview:lineView];

//需带上后缀名

if (button != btn ) {

其实这两种方式在大多数情况是一样,不用纠结。

}

}

- (void)confingTopView{

CGRect rc =[self.view convertRect:btn.frame fromView:btn.superview];

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,KTopViewHight - 1 , kWindowWidth, 1)];

23.高效设置圆角

self.bottomScrollView = [[UIScrollView alloc]initWithFrame:bottomScrollViewFrame];

btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//设置文字位置,现设为居左,默认的是居中

CGRect  VCFrame = CGRectMake(i * kWindowWidth, 0, kWindowWidth, bottomScrollViewFrame.size.height);

解决方法:

for (int i = 0; i < self.vcArray.count ; i ++) {

35.在UINavigationController中设置问题

- (void)configBottomView{

NSMutableString *mutableString =[[NSMutableString alloc]initWithData:data encoding:enc];

[self configBottomView];

解决方法:

button.tag = i;

让系统去调用application.window的rootViewController的preferredStatusBarStyle方法,如果rootViewController的childViewControllerForStatusBarStyle返回值不为nil,则参考上面的讲解。

}

1.注册通知:

// 按钮高度

在navigationBar上addSubView该UIView即可。

.h

CGFloat finalEndUser = endUsrY - self.view.frame.size.height;

CGRect topViewFrame = CGRectMake(0, 0, kWindowWidth, KTopViewHight

2.Library:1:电影,音乐,图片,报刊,电子书等等等<2>Preferences文件夹(会被同步),配置文件。

for (UIButton * btn in _btnArray) {

[cancalBtn setTitle:@"取消" forState:UIControlStateNormal];

self.topView = [[UIView alloc]initWithFrame:topViewFrame];

解决方法:当键盘弹起时,系统会经过注册的观察者发出一个通知。

[_bottomScrollView setContentOffset:CGPointMake(button.tag * kWindowWidth, 0) animated:YES];

} else if(scrollView.contentOffset.y >= sectionHeaderHeight){

[button setTitle:buttonTitle forState:UIControlStateNormal];

在Building setting中搜索Prefix Header,将它改为:$(SRCROOT)/项目名/…具体路径/pch文件名

}

举例:

.m

从名字很容易看出来代表的意思,使用“|”来组合就好了。

self.bottomScrollView.showsVerticalScrollIndicator = NO;

4.在Navigation上自定义了右边按钮,如何取得该按钮对象。以及该按钮的属性设定。

self.slideView = [[UIView alloc] initWithFrame:CGRectMake(0, KTopViewHight - 3, buttonWight, 3)];

[[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0,-60)forBarMetrics:UIBarMetricsDefault];

[self addSubview:_bottomScrollView];

修改之前一定要打开取消按钮才能遍历修改。

CGRect  bottomScrollViewFrame = CGRectMake(0, KTopViewHight, kWindowWidth, kWindowHeight - KTopViewHight );

}

int pageNum = scrollView.contentOffset.x / kWindowWidth;

解决方法:

self.bottomScrollView.contentSize = CGSizeMake(self.vcArray.count * kWindowWidth, 0);

不能太大,如果太大,可能上架时会被拒绝);

#import "CBSlideView.h"#define UIColorRGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]#define kWindowWidth                        ([[UIScreen mainScreen] bounds].size.width)#define kWindowHeight                      ([[UIScreen mainScreen] bounds].size.height)#define KTopViewHight 50@interface CBSlideView()@property (nonatomic,strong) UIScrollView * bottomScrollView;

2.同时在(UITableViewCell)*tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath代理方法中对scrollView把延迟触摸设置为NO即可**

for (UIButton * btn in _btnArray) {

26.Cell高度自适应:

_btnArray = [NSMutableArray array];

32.iOS上更改状态栏(UIStatusBar)的颜色**

self.vcArray = viewControllers;

currentPoint =[self convertPoint:currentPoint toView:_myView];

[self confingTopView];

//计算总高度

self.bottomScrollView.delegate =self;

btn =[[UIButton alloc]initWithFrame:CGRectMake(5,5,200,40)];

);

6.计算UITextView中的行数。

}

}

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(i * buttonWight, 0, buttonWight, buttonhight)];

注意:

_vcArray = vcArray;

或者

frame.origin.x = scrollView.contentOffset.x/_vcArray.count;

-(void)scrollViewDidScroll:(UIScrollView *)scrollView时两个视图各自滚动时都会掉用该方法。可能会产生不必要的bug。

-(void) tabButton: (id) sender{

NSAppTransportSecurity

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

本文由胜博发-编程发布,转载请注明来源://添加按钮澳门博发娱乐官网,这里需要加上大括