• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

LXR_BaiSi: 仿写百思不得姐客户端

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

LXR_BaiSi

开源软件地址:

https://gitee.com/ios67/LXR_BaiSi

开源软件介绍:

#LXR_BaiSi

BSBDJ 百思不得姐相关知识点

####解决图片渲染问题

  • 方法1.解决图片渲染问题
    UIImage* image = [UIImage imageNamed:@"tabBar_essence_click_icon"];//设置image模式是原始效果,不要渲染    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    vc1.tabBarItem.selectedImage = image;
  • 方法2.解决图片渲染问题

解决图片渲染问题

####修改项目名称

修改项目名称

####通过appearance同一设置所有UITabBarItem的文字属性

    NSMutableDictionary* attrs = [NSMutableDictionary new];    //文字 字体大小    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];    //文字 Foreground前景颜色    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];    NSMutableDictionary* selectesAttrs = [NSMutableDictionary new];    selectesAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];    selectesAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];    UITabBarItem* item = [UITabBarItem appearance];    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];    [item setTitleTextAttributes:selectesAttrs forState:UIControlStateSelected];

1

####设置cell默认选中第一行

 //设置左边列表cell默认选中首行    [self.LeftTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];

####李明杰第三方转模型框架使用

//通过数组responseObject[@"list"]进行转模型LXRRecommendLeftModel到LeftDataArray数组里        self.LeftDataArray = [LXRRecommendLeftModel mj_objectArrayWithKeyValuesArray:responseObject[@"list"]];

####重写方法

#pragma mark - 重写选中方法,系统默认选中将所有子控件显示为高亮状态---------重点//selected会打印出选中第几组第几行信息/**可以在这个方法中监听cell的选中和取消选中*/-(void)setSelected:(BOOL)selected animated:(BOOL)animated{    [super setSelected:selected animated:animated];    self.SelctedView.hidden = !selected;    //设置文字颜色,如果是选中状态是红色,如果不是就是正常颜色    self.textLabel.textColor = selected ? LXR_RGB_Color(219, 21, 26) : LXR_RGB_Color(78, 78,78);    //设置正常状态下文本颜色    //self.textLabel.textColor = LXR_RGB_Color(78, 78, 78);    //默认选中cell时textLable就会变成高亮颜色    //self.textLabel.highlightedTextColor = LXR_RGB_Color(219, 21, 26);}

####pch文件设置

//调试#ifdef DEBUG#define LXRLog(...) NSLog(__VA_ARGS__)#else#define LXRLog(...)#endif//打印执行方法#define LXRLogFunc LXRLog(@"%s",__func__)//设置颜色#define LXR_RGB_Color(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

####自定义NavigationController 重写方法

//可以在这个方法中拦截所有PUSH进来的控制器-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{    //统一设置控制器返回按钮的文字    if (self.childViewControllers.count > 0) { //如果push进来的不是第一个控制器        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];        //设置文字 颜色        [button setTitle:@"返回" forState:UIControlStateNormal];        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];        //设置按钮图片        [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];        //设置按钮大小,一定要设置大小,不然显示不出来        button.Size = CGSizeMake(60, 30);        //让按钮内容的所有内容左对齐        //button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;        //根据大小填充 建议使用        [button sizeToFit];        //设置按钮贴着屏幕左边  ---------重点!!!        button.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);        //添加点击事件  返回界面功能        [button addTarget:self action:@selector(Back) forControlEvents:UIControlEventTouchUpInside];        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];        //当push下一界面的时候,隐藏tabBar        viewController.hidesBottomBarWhenPushed = YES;    }    //这句super的push要放在后面,让viewController可以覆盖上面设置的leftBarButtonItem    [super pushViewController:viewController animated:animated];}

####重写initialize方法 作用

#pragma mark - 设置主题 这个方法只调用一次+(void)initialize{    //通过appearance同一设置所有UITabBarItem的文字属性    NSMutableDictionary* attrs = [NSMutableDictionary new];    //文字 字体大小    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];    //文字 Foreground前景颜色    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];    NSMutableDictionary* selectesAttrs = [NSMutableDictionary new];    selectesAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];    selectesAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];    UITabBarItem* item = [UITabBarItem appearance];    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];    [item setTitleTextAttributes:selectesAttrs forState:UIControlStateSelected];}

####重写setFrame和setBounds方法作用

/** *  需要重写setFrame和setBounds方法作用: *  重新布局cell,拦截设置方法后进行重新赋值,别人无法改变 */-(void)setFrame:(CGRect)frame{    //cell效果,x往右移动10,宽度减少2倍的x,高度减少1    frame.origin.x = 10;    frame.size.width -= 2*frame.origin.x;    frame.size.height -= 1;    [super setFrame:frame];}-(void)setBounds:(CGRect)bounds{    //cell效果,x往右移动10,宽度减少2倍的x,高度减少1    bounds.origin.x = 10;    bounds.size.width -= 2*bounds.origin.x;    bounds.size.height -= 1;    [super setBounds:bounds];}

####修改UITextField的placeholder颜色

  • 使用属性
@property(nonatomic,copy)   NSAttributedString     *attributedPlaceholder;// 文字属性NSMutableDictionary *attrs = [NSMutableDictionary dictionary];attrs[NSForegroundColorAttributeName] = [UIColor grayColor];// NSAttributedString : 带有属性的文字(富文本技术)NSAttributedString *placeholder = [[NSAttributedString alloc] initWithString:@"手机号" attributes:attrs];self.phoneField.attributedPlaceholder = placeholder;NSMutableAttributedString *placehoder = [[NSMutableAttributedString alloc] initWithString:@"手机号"];[placehoder setAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} range:NSMakeRange(0, 1)];[placehoder setAttributes:@{                            NSForegroundColorAttributeName : [UIColor yellowColor],                            NSFontAttributeName : [UIFont systemFontOfSize:30]                            } range:NSMakeRange(1, 1)];[placehoder setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} range:NSMakeRange(2, 1)];self.phoneField.attributedPlaceholder = placehoder;
  • 重写方法
- (void)drawPlaceholderInRect:(CGRect)rect{    [self.placeholder drawInRect:CGRectMake(0, 10, rect.size.width, 25) withAttributes:@{                                                       NSForegroundColorAttributeName : [UIColor grayColor],                                                       NSFontAttributeName : self.font}];}
  • 使用KVC
[self setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];

运行时(Runtime)

  • 苹果官方一套C语言库
  • 能做很多底层操作(比如访问隐藏的一些成员变量\成员方法....)
  • 访问成员变量举例
unsigned int count = 0;// 拷贝出所有的成员变量列表Ivar *ivars = class_copyIvarList([UITextField class], &count);for (int i = 0; i<count; i++) {    // 取出成员变量    // Ivar ivar = *(ivars + i);    Ivar ivar = ivars[i];    // 打印成员变量名字    XMGLog(@"%s", ivar_getName(ivar));}// 释放free(ivars);

ivars

利用pod trunk发布程序


注册
  • pod trunk register 邮箱 '用户名' --description='电脑描述'
查收邮件
接下来查看个人信息
  • pod trunk me
  - Name:     MJ Lee  - Email:    [email protected]  - Since:    January 28th, 03:53  - Pods:     None  - Sessions:    - January 28th, 04:28 - June 5th, 04:34. IP: xxx.xxx.xxx.xxx Description: Macbook Pro
  • 中间可能遇到这种错误
NoMethodError - undefined method 'last' for #<Netrc::Entry:0x007fc59c246378>
  • 这时候需要尝试更新gem源或者pod
    • sudo gem update --system
    • sudo gem install cocoapods
    • sudo gem install cocospods-trunk
创建podspec文件
  • 接下来需要在项目根路径创建一个podspec文件来描述你的项目信息
    • pod spec cretae 文件名
    • 比如pod spec cretae MJExtension就会生成一个MJExtension.podspec
填写podspec内容
Pod::Spec.new do |s|  s.name         = "MJExtension"  s.version      = "0.0.1"  s.summary      = "The fastest and most convenient conversion between JSON and model"  s.homepage     = "https://github.com/CoderMJLee/MJExtension"  s.license      = "MIT"  s.author             = { "MJLee" => "[email protected]" }  s.social_media_url   = "http://weibo.com/exceptions"  s.source       = { :git => "https://github.com/CoderMJLee/MJExtension.git", :tag => s.version }  s.source_files  = "MJExtensionExample/MJExtensionExample/MJExtension"  s.requires_arc = trueend
  • 值得注意的是,现在的podspec必须有tag,所以最好先打个tag,传到github
    • git tag 0.0.1
    • git push --tags
检测podspec语法
  • pod spec lint MJExtension.podspec
发布podspec
检测
  • pod setup : 初始化
  • pod repo update : 更新仓库
  • pod search MJExtension
仓库更新
  • 如果仓库更新慢,可以考虑更换仓库镜像
    • pod repo remove master
    • pod repo add master http://git.oschina.net/akuandev/Specs.git

UIMenuController的示例

UIMenuController

UIMenuController须知

  • 默认情况下, 有以下控件已经支持UIMenuController
    • UITextField
    • UITextView
    • UIWebView

让其他控件也支持UIMenuController(比如UILabel)

  • 自定义UILabel
  • 重写2个方法
/** * 让label有资格成为第一响应者 */- (BOOL)canBecomeFirstResponder{    return YES;}/** * label能执行哪些操作(比如copy, paste等等) * @return  YES:支持这种操作 */- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{    if (action == @selector(cut:) || action == @selector(copy:) || action == @selector(paste:)) return YES;    return NO;}
  • 实现各种操作方法
- (void)cut:(UIMenuController *)menu{    // 将自己的文字复制到粘贴板    [self copy:menu];    // 清空文字    self.text = nil;}- (void)copy:(UIMenuController *)menu{    // 将自己的文字复制到粘贴板    UIPasteboard *board = [UIPasteboard generalPasteboard];    board.string = self.text;}- (void)paste:(UIMenuController *)menu{    // 将粘贴板的文字 复制 到自己身上    UIPasteboard *board = [UIPasteboard generalPasteboard];    self.text = board.string;}
  • 让label成为第一响应者
// 这里的self是label[self becomeFirstResponder];
  • 显示UIMenuController
UIMenuController *menu = [UIMenuController sharedMenuController];// targetRect: MenuController需要指向的矩形框// targetView: targetRect会以targetView的左上角为坐标原点[menu setTargetRect:self.bounds inView:self];// [menu setTargetRect:self.frame inView:self.superview];[menu setMenuVisible:YES animated:YES];

自定义UIMenuController内部的Item

  • 添加item
// 添加MenuItem(点击item, 默认会调用控制器的方法)UIMenuItem *ding = [[UIMenuItem alloc] initWithTitle:@"顶" action:@selector(ding:)];UIMenuItem *replay = [[UIMenuItem alloc] initWithTitle:@"回复" action:@selector(replay:)];UIMenuItem *report = [[UIMenuItem alloc] initWithTitle:@"举报" action:@selector(report:)];menu.menuItems = @[ding, replay, report];

自定义布局 - 继承UICollectionViewFlowLayout

重写prepareLayout方法

  • 作用:在这个方法中做一些初始化操作
  • 注意:一定要调用[super prepareLayout]

重写layoutAttributesForElementsInRect:方法

  • 作用:
    • 这个方法的返回值是个数组
    • 这个数组中存放的都是UICollectionViewLayoutAttributes对象
    • UICollectionViewLayoutAttributes对象决定了cell的排布方式(frame等)

重写shouldInvalidateLayoutForBoundsChange:方法

  • 作用:如果返回YES,那么collectionView显示的范围发生改变时,就会重新刷新布局
  • 一旦重新刷新布局,就会按顺序调用下面的方法:
    • prepareLayout
    • layoutAttributesForElementsInRect:

重写targetContentOffsetForProposedContentOffset:withScrollingVelocity:方法

  • 作用:返回值决定了collectionView停止滚动时最终的偏移量(contentOffset)
  • 参数:
    • proposedContentOffset:原本情况下,collectionView停止滚动时最终的偏移量
    • velocity:滚动速率,通过这个参数可以了解滚动的方向

####2种方法设置按钮四周圆角

  • 方法1:代码实现

    代码实现

  • 方法2:KVC视图设置

    KVC

####找出类隐藏属性列表方法

  • 查找方法
//导入系统头文件#import <objc/runtime.h>@implementation LXRInputField//此方法只调用一次+(void)initialize{    unsigned int count = 0;    //拷贝出所有成员变量列表    //查找哪个类就传参输入[类名 class]    Ivar* ivars = class_copyIvarList([UITextField class], &count);    //遍历    for (int i =0; i<count; i++) {        //取出成员变量        Ivar ivar = *(ivars + i);        //打印成员变量名字        LXRLog(@"%s",ivar_getName(ivar));    }    //释放    free(ivars);}
  • 打印隐藏属性
2016-06-15 17:44:22.718 01- 百思不得姐[6934:96066] _textStorage2016-06-15 17:44:22.719 01- 百思不得姐[6934:96066] _borderStyle2016-06-15 17:44:22.719 01- 百思不得姐[6934:96066] _minimumFontSize2016-06-15 17:44:22.719 01- 百思不得姐[6934:96066] _delegate2016-06-15 17:44:22.720 01- 百思不得姐[6934:96066] _background2016-06-15 17:44:22.720 01- 百思不得姐[6934:96066] _disabledBackground2016-06-15 17:44:22.720 01- 百思不得姐[6934:96066] _clearButtonMode2016-06-15 17:44:22.720 01- 百思不得姐[6934:96066] _leftView2016-06-15 17:44:22.720 01- 百思不得姐[6934:96066] _leftViewMode2016-06-15 17:44:22.721 01- 百思不得姐[6934:96066] _rightView2016-06-15 17:44:22.721 01- 百思不得姐[6934:96066] _rightViewMode2016 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap