中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

iOS7 UITableView做成類似iOS6風格

發布時間:2020-06-17 02:20:44 來源:網絡 閱讀:11836 作者:zmhot88 欄目:移動開發

iOS7扁平化設計已經成為了一個趨勢基于對老版本的臨時修改UITableView在sytle是group的時候是個×××煩沒辦法改就改吧。

       直接用圖片的方式是最簡單的設置一個背景圖拖一個UIImageView到你的Custom Cell中去設置普通和高亮情況下的p_w_picpath針對iOS7修改內部元素的frame設置默認的北京view為空代碼如下

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...........
    UIView *testView2 = [[UIView alloc] init];
    testView2.backgroundColor = UIColor.clearColor;
    cell.selectedBackgroundView = testView2;
    ......
}

這樣基本就OK了。

       我在另一個文章里看到的方法確實通過自己寫代碼來實現大部分功能我覺得相對比較好但是很多陰影效果還是需要在研究研究的。主要是修改custom cell的setFrame,和修改tableview的

willDisplayCell來看看這兩段代碼

//custom 重寫setFrame方法當然該方法最好針對iOS7才有效。

#define IOS7_OR_LATER   ( [[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending )
- (void)setFrame:(CGRect)frame {
    if (IOS7_OR_LATER) {
        NSInteger inset = 10;
        frame.origin.x += inset;
        frame.size.width -= 2 * inset;
    }
    [super setFrame:frame];
}

然后寫UITableViewDelegate的回調函數

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(tintColor)]) {
        if (tableView == self.vTableView) {
            CGFloat cornerRadius = 10.f;
            cell.backgroundColor = UIColor.clearColor;
            CAShapeLayer *layer = [[CAShapeLayer alloc] init];
            CAShapeLayer *borderLayer = [[CAShapeLayer alloc] init];
            CAShapeLayer *selectedLayer = [[CAShapeLayer alloc] init];
                           
            CGMutablePathRef borderPathRef = CGPathCreateMutable();
            CGRect bounds0 = CGRectInset(cell.bounds, 0, 0);
            NSLog(@"bound0:%@",NSStringFromCGRect(cell.frame));
            if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                CGPathAddRoundedRect(borderPathRef, nil, bounds0, cornerRadius, cornerRadius);
            } else if (indexPath.row == 0) {
                CGPathMoveToPoint(borderPathRef, nil, CGRectGetMinX(bounds0), CGRectGetMaxY(bounds0));//left bottom
                CGPathAddArcToPoint(borderPathRef, nil, CGRectGetMinX(bounds0), CGRectGetMinY(bounds0), CGRectGetMidX(bounds0), CGRectGetMinY(bounds0), cornerRadius);
                CGPathAddArcToPoint(borderPathRef, nil, CGRectGetMaxX(bounds0), CGRectGetMinY(bounds0), CGRectGetMaxX(bounds0), CGRectGetMidY(bounds0), cornerRadius);
                CGPathAddLineToPoint(borderPathRef, nil, CGRectGetMaxX(bounds0), CGRectGetMaxY(bounds0));
            } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                CGPathMoveToPoint(borderPathRef, nil, CGRectGetMinX(bounds0), CGRectGetMinY(bounds0));//left top
                CGPathAddArcToPoint(borderPathRef, nil, CGRectGetMinX(bounds0), CGRectGetMaxY(bounds0), CGRectGetMidX(bounds0), CGRectGetMaxY(bounds0), cornerRadius);
                CGPathAddArcToPoint(borderPathRef, nil, CGRectGetMaxX(bounds0), CGRectGetMaxY(bounds0), CGRectGetMaxX(bounds0), CGRectGetMidY(bounds0), cornerRadius);
                CGPathAddLineToPoint(borderPathRef, nil, CGRectGetMaxX(bounds0), CGRectGetMinY(bounds0));
            } else {
                CGPathAddRect(borderPathRef, nil, CGRectInset(cell.bounds, 0, 1));
            }
            borderLayer.path = borderPathRef;
            CFRelease(borderPathRef);
            cornerRadius = 7.f;
            CGMutablePathRef pathRef = CGPathCreateMutable();
            CGRect bounds = CGRectInset(cell.bounds, 1, 1);
            BOOL addLine = NO;
            if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
            } else if (indexPath.row == 0) {
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds0));
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds0));
                addLine = YES;
            } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds0));
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds0));
            } else {
                CGPathAddRect(pathRef, nil, CGRectInset(cell.bounds, 1, 0));
                addLine = YES;
            }
            layer.path = pathRef;
            selectedLayer.path = pathRef;
            CFRelease(pathRef);
            layer.fillColor = [UIColor whiteColor].CGColor;
            selectedLayer.fillColor = [UIColor redColor].CGColor;
                           
            borderLayer.zPosition = 0.0f;
            borderLayer.strokeColor = [UIColor blueColor].CGColor;
            borderLayer.lineWidth = 1;
            borderLayer.lineCap = kCALineCapRound;
            borderLayer.lineJoin = kCALineJoinRound;
                           
            [borderLayer addSublayer:layer];
                           
            if (addLine == YES) {
                CALayer *lineLayer = [[CALayer alloc] init];
                CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
                lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+1, bounds0.size.height-lineHeight, bounds0.size.width-2, lineHeight);
                lineLayer.backgroundColor = tableView.separatorColor.CGColor;
                [layer addSublayer:lineLayer];
            }
            //add general view
            UIView *testView = [[UIView alloc] initWithFrame:bounds];
            [testView.layer insertSublayer:borderLayer atIndex:0];
            testView.backgroundColor = UIColor.clearColor;
            cell.backgroundView = testView;
                           
            //add selected layer view;
            UIView *testView2 = [[UIView alloc] initWithFrame:bounds];
            [testView2.layer insertSublayer:selectedLayer atIndex:0];
            testView2.backgroundColor = UIColor.clearColor;
            cell.selectedBackgroundView = testView2;
        }
    }
}

代碼至此結束看看最終的效果圖吧

iOS7 UITableView做成類似iOS6風格

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

于都县| 天津市| 景德镇市| 延安市| 丘北县| 达州市| 武穴市| 乾安县| 永寿县| 安图县| 成武县| 垣曲县| 禹城市| 桑日县| 文水县| 巴林左旗| 汉寿县| 西乡县| 库车县| 卓资县| 河津市| 抚顺县| 普洱| 巴楚县| 罗甸县| 新乡县| 七台河市| 肥西县| 邳州市| 通辽市| 美姑县| 竹溪县| 勃利县| 黎平县| 赣榆县| 华池县| 临清市| 拉萨市| 泗阳县| 周至县| 手机|