登录

ios - 请问这种带尖角的view有什么好的实现方法

# iOS
伊谢尔伦伊谢尔伦2139 天前722 次浏览

全部回复(8) 我要回复

  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:51:55

    程序猿的解决方法是;创建一个正方形的 view ; 背景颜色 和 那个主框颜色相同。 然后; 将这个 正方形 view 旋转 90 度。 添加到 主框中。指定位置 即可。也就是,这个样式是两个 view 拼出来的。

    回复
    0
  • ringa_lee

    ringa_lee2017-04-18 09:51:55

    做一个气泡图片,然后放个tableView在里面,做好固定的约束和图片的slicing设置后,可以试试这样行不行??

    回复
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:51:55

    可以画一个出来,省了切图资源,效率也更高,方便复用。

    - (UIView *)arrowView{
        if (!_arrowView) {
            // draw
            CGSize size = CGSizeMake(kDefaultArrowWeight, kDefaultArrowHeight);
            UIBezierPath *path = [[UIBezierPath alloc] init];
            [path moveToPoint:CGPointMake(size.width / 2.0, 0)];
            [path addLineToPoint:CGPointMake(0, size.height)];
            [path addLineToPoint:CGPointMake(size.width, size.height)];
            path.lineWidth = 1.0;
            
            CAShapeLayer *arrowLayer = [CAShapeLayer layer];
            arrowLayer.path = path.CGPath;
            
            _arrowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            _arrowView.layer.mask = arrowLayer;
            _arrowView.backgroundColor = self.contentViewBackgroundColor;
        }
        return _arrowView;
    }

    回复
    0
  • PHPzhong

    PHPzhong2017-04-18 09:51:55

    UIView上面贴一个三角的imageview,上面再贴tableview。这样滚动也没有问题,如果要调整imageView的位置也没有问题。

    回复
    0
  • 高洛峰

    高洛峰2017-04-18 09:51:55

    HTML:

    <p class="test_triangle_border">
        <a href="#">三角形</a>
        <p class="popup">
            <span><em></em></span>测试
        </p>
    </p>
    

      

    CSS:

    .test_triangle_border{
        width:200px;
        margin:0 auto 20px;
        position:relative;
    }
    .test_triangle_border a{
        color:#333;
        font-weight:bold;
        text-decoration:none;
    }
    .test_triangle_border .popup{
        width:100px;
        background:#cf0;
        padding:10px 20px;
        color:#333;
        border-radius:4px;
        position:absolute;
        top:30px;
        left:30px;
        border:1px solid #333;
    }
    .test_triangle_border .popup span{
        display:block;
        width:0;
        height:0;
        border-width:0 10px 10px;
        border-style:solid;
        border-color:transparent transparent #333;
        position:absolute;
        top:-10px;
        left:50%;/* 三角形居中显示 */
        margin-left:-10px;/* 三角形居中显示 */
    }
    .test_triangle_border .popup em{
        display:block;
        width:0;
        height:0;
        border-width:0 10px 10px;
        border-style:solid;
        border-color:transparent transparent #cf0;
        position:absolute;
        top:1px;
        left:-10px;
    }
    

    这是我答过别的的答案, 自己根据需求改吧

    回复
    0
  • 怪我咯

    怪我咯2017-04-18 09:51:55

    这是个控件,iPad专用的.叫UIPopoverController.

    回复
    0
  • 阿神

    阿神2017-04-18 09:51:55

    是iOS8的话 可以用UIPopoverPresentationController

    回复
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:51:55

    美工 要个 图片解决

    回复
    0
  • 取消回复发送