自定义 RatingView IOS 中未显示 Star-Half 图像

Posted

技术标签:

【中文标题】自定义 RatingView IOS 中未显示 Star-Half 图像【英文标题】:Star-Half image is not displaying in Custom RatingView IOS 【发布时间】:2015-01-20 11:36:42 【问题描述】:

我正在使用本教程 http://www.raywenderlich.com/1768/uiview-tutorial-for-ios-how-to-make-a-custom-uiview-in-ios-5-a-5-star-rating-view 自定义评分栏。但我不能给半分。当用户触摸 imageview 时,我试图显示半星。请给我建议

【问题讨论】:

使用这个库:github.com/dlinsin/DLStarRating @AshishKakkad- 有没有办法修复该教程?对我最好? 【参考方案1】:

终于解决了半星问题。

if (!self.editable) return;

//The rating starts out as 0 and then builds from there.
CGFloat newRating = 0;
//loop through the image collection backwards so if it exits the loop it will have identified the MAX
for(int i = self.imageViews.count - 1; i >= 0; i--) 
    UIImageView *imageView = [self.imageViews objectAtIndex:i];

    CGFloat distance = touchLocation.x - imageView.frame.origin.x;

    CGFloat frameWidth = imageView.frame.size.width;

    if (distance <= 0)
        //this means that the click was to the left of the frame
       continue;
    
    if (distance /frameWidth >.75) 
        //If this ratio is >.75 then you are to the right 3/4 of the image or past th image
        newRating = i + 1;
        break;
     else 
        //you didn't drop out or mark the entire star, so mark it half.
        newRating = i + 0.5;
        break;
    


self.rating = newRating;

【讨论】:

以上是关于自定义 RatingView IOS 中未显示 Star-Half 图像的主要内容,如果未能解决你的问题,请参考以下文章

自定义按钮在界面生成器中未正确显示

推送通知在 ios 9 中未显示 2kb

iOS:iCarousel 中未选择视图的约束

Silverlight 中未显示某些自定义字体

Post Gutenberg 编辑器中未显示自定义分类法

Leaflet.js 中未显示自定义 Mapbox 瓦片集