分类 移动开发 下的文章

ionic开发的几个小坑

之前做个小移动客户端,图方便快捷,使用了ionic来开发,整体还是挺顺畅的,就是不太习惯yong其中碰到一些小坑,
都是一些知道了就很简单,不知道就很蛋疼的东西,所以做个笔记,帮初次接触ionic和angularjs的人省点事儿
1.ionic中的CORS(跨域)问题
这个问题一般刚接触ionic的都会遇到,在浏览器中通过ionic serve调试的时候,请求api时会报错

XMLHttpRequest cannot load http://localhost:8080/api/p/1. No
'Access-Control-Allow-Origin' header is present on the requested

  1. Origin 'http://localhost:8100' is therefore not allowed
    access.





- 阅读剩余部分 -

自定义UITableViewCell的高度自适应

项目里需要实现UITableView的Cell的高度自适应,google后发现都是基于默认cell的处理,对于自定义的UITableViewCell没有效果,稍微研究了一下代码,发现,关键还是在计算UILabel的高度上,于是稍微对网上现成的代码做了写修改,实现了需要的功能。
要实现的效果如下:

donelist.png

自定义的cell也很简单,一排label,简单的表格效果:

celldemo.png

简单贴一下关键代码,做为备忘:

1、设置全局变量来保存每行高度,目的是避免重复计算高度

@property (nonatomic, retain) NSMutableArray *cellHeightList;
@synthesize cellHeightList;
- (void)viewDidLoad
{
    [super viewDidLoad];
    //初始化
    self.cellHeightList = [[NSMutableArray alloc] init];
}

<br/>
2、计算每行cell高度,并保存高度列表
<br/>

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    int row = [indexPath row];
    //设置字体信息
    UIFont *textfont15 = [UIFont systemFontOfSize:15];
    //选取几个可能内容比较多的label值
    Category *category = (Category *)[self.personList objectAtIndex:indexPath.section];
    NSDictionary *rowData = [category.list objectAtIndex:row];
    NSString *pnowContent = [rowData objectForKey:@"ppositionnow"];
    NSString *pfurContent = [rowData objectForKey:@"ppositionfur"];
    NSString *pcancelContent = [rowData objectForKey:@"ppositioncancel"];
    NSString *degreeContent = [rowData objectForKey:@"pdegree"];
    NSString *infoContent = [rowData objectForKey:@"potherinfo"];
    
    // 分别计算显示这些内容的几个label所需要的最小尺寸
    //169.0f;104.0f;145.0f为label的宽度
    CGSize pnowsize = [pnowContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(168.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
    CGSize pfursize = [pfurContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(168.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
    CGSize pcansize = [pcancelContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(168.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
    CGSize degsize = [degreeContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(104.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];
    CGSize infosize = [infoContent sizeWithFont:textfont15 constrainedToSize:CGSizeMake(145.0f, 1000.0f) lineBreakMode:NSLineBreakByWordWrapping];

    //保存不同label高度值
    NSMutableArray *heightArray = [[NSMutableArray alloc] initWithCapacity:5];
    [heightArray addObject:[NSNumber numberWithFloat:pnowsize.height]];
    [heightArray addObject:[NSNumber numberWithFloat:pfursize.height]];
    [heightArray addObject:[NSNumber numberWithFloat:pcansize.height]];
    [heightArray addObject:[NSNumber numberWithFloat:degsize.height]];
    [heightArray addObject:[NSNumber numberWithFloat:infosize.height]];
    //初始化最大高度值
    NSNumber *max_height = [NSNumber numberWithInt:50];
    //比较,找出最大高度做为cell的高度
    for (int i=0;i<[heightArray count];i++){
        if ([[heightArray objectAtIndex:i] intValue]>[max_height intValue]) {
            max_height = [heightArray objectAtIndex:i];
        }
    }
        
    //保存cell高度到全局变量
    [self.cellHeightList addObject:[NSNumber numberWithFloat:[max_height floatValue]+30]];

    return [max_height floatValue]+30.0;    
    
}

<br/>
3、设置cell内UILabel的高度
<br/>

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

    NSDictionary *rowData = [category.list objectAtIndex:nowrow];
    NSString *pnameContent = [rowData objectForKey:@"pname"];
    NSString *pnowContent = [rowData objectForKey:@"ppositionnow"];
    NSString *pfurContent = [rowData objectForKey:@"ppositionfur"];
    NSString *pcancelContent = [rowData objectForKey:@"ppositioncancel"];
    NSString *genderContent = [rowData objectForKey:@"pgender"];
    NSString *degreeContent = [rowData objectForKey:@"pdegree"];
    NSString *birthContent = [rowData objectForKey:@"pbirth"];
    NSString *partyContent = [rowData objectForKey:@"pparty"];
    NSString *infoContent = [rowData objectForKey:@"potherinfo"];
    //获取当前cell高度
    float labelHeight = [[self.cellHeightList objectAtIndex:nowrow] floatValue];
    //当前label信息
    CGRect pnameFrame = cell.PersonNameLabel.frame;
    CGRect pnowFrame = cell.PositionNowLabel.frame;
    CGRect pfurFrame = cell.PositionFurLabel.frame;
    CGRect pcanFrame = cell.PositionCancelLabel.frame;
    CGRect genderFrame = cell.GenderLabel.frame;
    CGRect degreeFrame = cell.DegreeLabel.frame;
    CGRect birthFrame = cell.BirthLabel.frame;
    CGRect partyFrame = cell.PartyLabel.frame;
    CGRect otherFrame = cell.OtherLabel.frame;
    //修改label的高度
    pnameFrame.size.height = labelHeight;
    pnowFrame.size.height = labelHeight;
    pfurFrame.size.height = labelHeight;
    pcanFrame.size.height = labelHeight;
    genderFrame.size.height = labelHeight;
    degreeFrame.size.height = labelHeight;
    birthFrame.size.height = labelHeight;
    partyFrame.size.height = labelHeight;
    otherFrame.size.height = labelHeight;
    //更新label的信息
    cell.PersonNameLabel.frame = pnameFrame;
    cell.PositionNowLabel.frame = pnowFrame;
    cell.PositionFurLabel.frame = pfurFrame;
    cell.PositionCancelLabel.frame = pcanFrame;
    cell.GenderLabel.frame = genderFrame;
    cell.DegreeLabel.frame = degreeFrame;
    cell.BirthLabel.frame = birthFrame;
    cell.PartyLabel.frame = partyFrame;
    cell.OtherLabel.frame = otherFrame;
    //设置label内容
    cell.PersonNameLabel.text = pnameContent;
    cell.PositionNowLabel.text = pnowContent;
    cell.PositionFurLabel.text = pfurContent;
    cell.PositionCancelLabel.text = pcancelContent;
    cell.GenderLabel.text = genderContent;
    cell.DegreeLabel.text = degreeContent;
    cell.BirthLabel.text = birthContent;
    cell.PartyLabel.text = partyContent;
    cell.OtherLabel.text = infoContent;

    ……
}

<br/>
编译运行,搞定……

mac截图快捷键

我会告诉你在这之前我都是先打开“预览”,然后再通过点击来选择截图功能的?

1. Command-Shift-3: 将整个屏幕拍下并保存到桌面。

2. Command-Shift-Control-3:将整个屏幕拍下并保存到剪贴板(Clipboard),然后Command+V直接粘贴到如Photoshop,ppt等软件中编辑。

3. Command-Shift-4:将屏幕的一部分拍下并保存到桌面。按下这个组合键后,光标会变为一个十字,你可以拖拉来选取拍摄区域。

4. Command-Shift-Control-4:将屏幕的一部分拍下并保存到剪贴板。

5. Command-Shift-4再按空格键:这时光标会变为一个照相机图标,点击可拍下当前窗口或菜单或Dock以及图标等,只要将照相机图标移动到不同区域(有效区域会显示为浅蓝色)点击。

6. Command-Shift-Control-4再按空格键:将选取的窗口或其他区域的快照保存到剪贴板。

- 阅读剩余部分 -

热评文章

最新文章

最近回复

归档

其它