IOS客户端Coding项目记录(二)

9:第三方插件整理

JSON转实体:jsonModel https://github.com/icanzilb/JSONModel/
美化按键:BButton   https://github.com/mattlawer/BButton
状态栏提示:JDStatusBarNotification https://github.com/jaydee3/JDStatusBarNotification
照片显示插件:MJPhotoBrowser  https://github.com/azxfire/MJPhotoBrowser
在列表行划动显示更多选项:SWTableViewCell   https://github.com/cewendel/swtableviewcell
图片查看插件:mwphotobrowser   https://github.com/mwaterfall/mwphotobrowser
滚动条插件:asprogresspopupview  https://github.com/alskipp/asprogresspopupview
时间处理:nsdate-helper  https://github.com/billymeltdown/nsdate-helper
各种进度条:m13progresssuite https://github.com/marxon13/m13progresssuite
弹出提示mbprogresshud:  https://github.com/jdg/mbprogresshud

10:button显示设置不同字体

[_headerFansCountBtn setAttributedTitle:[self getStringWithTitle:@"粉丝" andValue:_curUser.fans_count.stringValue] forState:UIControlStateNormal];

方法(根据长度来设置其不同的样式显示):

- (NSMutableAttributedString*)getStringWithTitle:(NSString *)title andValue:(NSString *)value{
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", title, value]];
    [attriString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15],
                                 NSForegroundColorAttributeName : [UIColor blackColor]}
                         range:NSMakeRange(0, title.length)];

    [attriString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15],
                                 NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x3bbd79"]}
                         range:NSMakeRange(title.length+1, value.length)];
    return  attriString;
}

11:UITableviewcell的accessoryType属性

cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式  
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button; 
cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号; 

12:layoutSubviews在以下情况下会被调用

a、init初始化不会触发layoutSubviews。
b、addSubview会触发layoutSubviews。
c、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化。
d、滚动一个UIScrollView会触发layoutSubviews。
e、旋转Screen会触发父UIView上的layoutSubviews事件。
f、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件。
g、直接调用setLayoutSubviews。

13:导航栏的按键(自定义图片)

UIButton *settingBtn = [self navButtonWithImageName:@"settingBtn_Nav" action:@selector(settingBtnClicked:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:settingBtn];

    UIButton *addUserBtn = [self navButtonWithImageName:@"addUserBtn_Nav" action:@selector(addUserBtnClicked:)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:addUserBtn];

14:自定义表格行(继承UITableViewCell)

@interface TitleRImageMoreCell ()
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UIImageView *userIconView;
@end
@implementation TitleRImageMoreCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        if (!_titleLabel) {
            _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, ([TitleRImageMoreCell cellHeight] -30)/2, 100, 30)];
            _titleLabel.backgroundColor = [UIColor clearColor];
            _titleLabel.font = [UIFont systemFontOfSize:16];
            _titleLabel.textColor = [UIColor blackColor];
            [self.contentView addSubview:_titleLabel];
        }
        if (!_userIconView) {
            _userIconView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreen_Width- kTitleRImageMoreCell_HeightIcon)- kPaddingLeftWidth- 30, ([TitleRImageMoreCell cellHeight] -kTitleRImageMoreCell_HeightIcon)/2, kTitleRImageMoreCell_HeightIcon, kTitleRImageMoreCell_HeightIcon)];
            [_userIconView doCircleFrame];
            [self.contentView addSubview:_userIconView];
        }
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    if (!_curUser) {
        return;
    }
    self.titleLabel.text = @"头像";
    [self.userIconView sd_setImageWithURL:[_curUser.avatar urlImageWithCodePathResizeToView:_userIconView] placeholderImage:kPlaceholderMonkeyRoundView(_userIconView)];
}

+ (CGFloat)cellHeight{
    return 70.0;
}

@end

然后进行调用时(可以属性传值,并在不同的地方加载不同的行及其高度):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        TitleRImageMoreCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleRImageMore forIndexPath:indexPath];
        cell.curUser = _curUser;
        [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
        return cell;
}
else
{
TitleValueMoreCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleValueMore forIndexPath:indexPath];
}
return cell;
}

15:当给按键的图标进行方向改变

[self setImage:[UIImage imageNamed:@"nav_arrow_down"] forState:UIControlStateNormal];
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, DEGREES_TO_RADIANS(180));//这这是进行180度转到,向下或向下

16:在导航栏中间增加一个带图片文字的控件

- (UIDownMenuButton *)initWithTitles:(NSArray *)titleList andDefaultIndex:(NSInteger)index andVC:(UIViewController *)viewcontroller{
    self = [super init];
    if (self) {
        _titleList = titleList;
        _curIndex = index;
        _curShowing = NO;
        _mySuperView = viewcontroller.view;

        self.backgroundColor = [UIColor clearColor];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        [self.titleLabel setFont:[UIFont systemFontOfSize:kNavTitleFontSize]];
        [self.titleLabel setMinimumScaleFactor:0.5];
        [self addTarget:self action:@selector(changeShowing) forControlEvents:UIControlEventTouchUpInside];
        [self refreshSelfUI];
    }
    return self;
}

- (void)refreshSelfUI{
    NSString *titleStr = @"";
    DownMenuTitle *menuObj = [self.titleList objectAtIndex:self.curIndex];
    titleStr = menuObj.titleValue;
    CGFloat titleWidth = [titleStr getWidthWithFont:self.titleLabel.font constrainedToSize:CGSizeMake(kScreen_Width, 30)];//获得文字的宽度
    CGFloat btnWidth = titleWidth +kNavImageWidth;
    self.frame = CGRectMake((kScreen_Width-btnWidth)/2, (44-30)/2, btnWidth, 30);

    self.titleEdgeInsets = UIEdgeInsetsMake(0, -kNavImageWidth, 0, kNavImageWidth);
    self.imageEdgeInsets = UIEdgeInsetsMake(0, titleWidth, 0, -titleWidth);
    [self setTitle:titleStr forState:UIControlStateNormal];
    [self setImage:[UIImage imageNamed:@"nav_arrow_down"] forState:UIControlStateNormal];
}

其中几个值:

#define  kNavTitleFontSize 19
#define kScreen_Width [UIScreen mainScreen].bounds.size.width
#define kNavImageWidth (15.0+5.0)

然后直接赋给titleview:

    UIDownMenuButton *navBtn = [[UIDownMenuButton alloc] initWithTitles:titleList andDefaultIndex:index andVC:self];
    navBtn.menuIndexChanged = block;
    self.navigationItem.titleView = navBtn;

注意:button都是有带文字跟图片的,只是图片都是在左边,要通过uiedgeinsetsmake对图片跟文字进行位置的改变。可以在导航栏的titleview做文章,放一些其它控件,或视图;

17:集合视图UICollectionView的简单使用

要遵循三个协议:UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout

设置单元格的布局
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setItemSize:CGSizeMake(70, 100)];//设置cell的尺寸
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);//设置其边界
//其布局很有意思,当你的cell设置大小后,一行多少个cell,由cell的宽度决定

然后设置集合视图:
_collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height) collectionViewLayout:flowLayout];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.backgroundColor = [UIColor clearColor];
    [_collectionView registerClass:[BMCollectionCell class] forCellWithReuseIdentifier:CELL_ID];
    [self.view addSubview:_collectionView];

注意:其它委托事件没全写出,比如numberOfSectionsInCollectionView等;
时间: 2024-08-09 22:07:27

IOS客户端Coding项目记录(二)的相关文章

IOS客户端Coding项目记录(四)

1:打开Xcode,然后闪退,报加载某库出现异常 如/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib 这个是Xcode的bug,我的情况是打开某个项目会出现这个问题 解决办法:这还是缓存问题,详见第五点(5.XCode5由于缓存问题引起了很多奇怪的问题,所以清除缓存有时会起到大作用:),清除缓存再运行,一切正常. 进入步骤,按option键进入

IOS客户端Coding项目记录(一)

1:UITextField设置出现清除按键 self.textField.clearButtonMode = UITextFieldViewModeWhileEditing; 说明: UITextField.clearButtonMode:清空输入的字符,有以下几种模式 UITextFieldViewModeAlways,不为空,获得焦点与没有获得焦点都显示清空按钮 UITextFieldViewModeNever,不显示清空按钮 UITextFieldViewModeWhileEditing,

IOS客户端Coding项目记录(五)

1:统一修改导航栏的样式,在 AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customiz

IOS客户端Coding项目记录(三)

18:图片视图几种填充样式 _imgView.contentMode = UIViewContentModeScaleAspectFill; 如下: typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, // re

ios客户端暑期“动画屋“活动项目总结

    入职实习的这个公司,第一天就分配了任务,从零开始写一个网页,之前虽然了解一些前端知识,但从头开写还是遇到了很多问题,互联网公司讲求效率,有deadline还是比较有紧迫感的,与在实验室放羊状态有了鲜明的对比.mentor.产品经理.组里的boss.实习生同事都给我提供了非常多的帮助.此篇总结为独立完成的第一个项目的项目总结.下图是已上线活动界面效果. 项目介绍 (一).爱奇艺IOS客户端发现-活动页面中"动画屋"活动开始页面的开发     活动开始页面的开发主要需求是:    

ios客户端发现_动画屋后期页面重构与悬浮评论分享模块开发项目总结

从"看世界杯送流量"项目,遇到响应式布局问题之后,专门钻研了这方面专业的书籍,同时阅读了相关文章.响应式布局简单的说就是使开发的页面在不同设备上都有友好的效果.而最开始"暑期动画屋"的项目,当时并没有采用响应式布局,虽然ipad上可用,其他设备则会有显示问题.这也暴露了,目前所在移动业务事业部前端的问题:    1.考虑到响应式布局在不同设备上,UI设计师只给了一套UI原型图,而在不同设备上的显示只是根据前端工程师的理解或个人偏好来完成布局.从产品经理的角度以及测试

ios客户端发现_世界杯送流量活动项目总结

   世界杯如火如荼的进行,视频网站类似于门户网站,需要快速根据外部环境更新内容.产品经理需要策划活动,并安排实施.这个活动就是在这样背景下产生的,爱奇艺与运营商合作,实现双赢.爱奇艺可以通过运营商向海量用户发送短信的方式,提高用户数,运营商通过爱奇艺视频平台给用户更多种多样的福利,提高用户黏性.   总的来说:运营商有用户,视频网站有内容.用户需要内容,有内容的需要用户,有用户的需要满足用户内容的需求.两者优点突出.需求明显合作水到渠成.另外爱奇艺将运营商作为大客户管理,保证了协同作战的机动性

搭建基于asp.net的wcf服务,ios客户端调用的实现记录

一.写wcf 问题: 1.特定的格式 2.数据绑定 3.加密解密 二.发布到iis 问题: 1.访问权限问题,添加everyone权限 访问网站时:http://localhost/WebbUploadSample/ZipUpload.aspx “/WebbUploadSample”应用程序中的服务器错误. -------------------------------------------------------------------------------- 访问被拒绝. 说明: 访问服

【HELLO MAKA】MAKA iOS客户端 之二 架构设计与实现篇

上一篇主要做了MAKA APP的需求分析,功能结构分解,架构分析,API分析,API数据结构分析. 这篇主要讲如何从零做iOS应用架构. [HELLO MAKA]MAKA iOS客户端 之一 APP分析篇 [HELLO MAKA]MAKA iOS客户端 之二 架构设计与实现篇 [HELLO MAKA]MAKA iOS客户端 之三 创作模块分析与实现篇 1.  iOS客户端架构 按照功能模块划分.这里可以使用二层设计也可以使用三层设计.MVC, MVCS, MVVM, MVP, VIPER, DD