2013-04-19 10 views
14

Czy są dostępne elementy sterujące do oceny gwiazdek w systemie ios? Więc mogę tego użyć w UITableviewCell?Czy są dostępne elementy sterujące do oceny gwiazdkowej?

Wiem, że istnieje kilka otwartych elementów sterujących open source, takich jak DYRating itp .. Ale nie jestem w stanie dodać go w komórce widoku tabeli.

+0

Spójrz na to http://www.raywenderlich.com/1768/how-to-make-a-custom-uiview-a-5-star-rating-view –

+0

Bhargavi: ale muszę dodać, że w uitableviewcell, aby każdy wiersz mógł podać dane wejściowe do tej gwiazdy, a następnie wyświetli gwiazdę odpowiadającą ocenie – Naveen

+0

Czy próbowałeś z tworzeniem CustomCells? –

Odpowiedz

11

Można sprawdzić rating ASStar.

Dodaj kontrolkę bezpośrednio do kontrolera widoku lub dodaj do swojej komórki.

A tutaj jest .

+0

jak zdobyć gwiazdę liczyć ,,,,,,, –

17

Polecam . Jest on natywny i obsługuje także IB_DESIGNABLE i IBInspectable.

HCSStarRatingView

+0

Dzięki za IBDesignable star rating control –

3

Uwaga: To jest "tylko wskazanie" jeden. STARS

Podjęłam inne podejście, stworzyłem etykietę z przypisanym ciągiem, używając czcionki z gwiazdkami, możesz sprawdzić tutaj moją kategorię.Kiedyś "SS Pika" font,

#import "NSMutableAttributedString+Stars.h" 

@implementation NSMutableAttributedString (Stars) 

+ (NSAttributedString *)starWithRating:(CGFloat)rating 
          outOfTotal:(NSInteger)totalNumberOfStars 
          withFontSize:(CGFloat) fontSize{ 
    UIFont *currentFont = [UIFont fontWithName:@"SS Pika" size:fontSize]; 
    NSDictionary *activeStarFormat = @{ 
              NSFontAttributeName : currentFont, 
              NSForegroundColorAttributeName : [UIColor redColor] 
              }; 
    NSDictionary *inactiveStarFormat = @{ 
              NSFontAttributeName : currentFont, 
              NSForegroundColorAttributeName : [UIColor lightGrayColor] 
              }; 

    NSMutableAttributedString *starString = [NSMutableAttributedString new]; 

    for (int i=0; i < totalNumberOfStars; ++i) { 
     //Full star 
     if (rating >= i+1) { 
      [starString appendAttributedString:[[NSAttributedString alloc] 
               initWithString:@"\u22C6 " attributes:activeStarFormat]]; 
     } 
     //Half star 
     else if (rating > i) { 
      [starString appendAttributedString:[[NSAttributedString alloc] 
               initWithString:@"\uE1A1 " attributes:activeStarFormat]]; 
     } 
     // Grey star 
     else { 
      [starString appendAttributedString:[[NSAttributedString alloc] 
               initWithString:@"\u22C6 " attributes:inactiveStarFormat]]; 
     } 

    } 
    return starString; 
} 
@end 

ZASTOSOWANIE:

self.ratingLabel.attributedText = [NSMutableAttributedString starWithRating:rating outOfTotal:5 withFontSize:9.0f]; 

Oto SWIFT Wersja

extension NSMutableAttributedString{ 

    func starWithRating(rating:Float, outOfTotal totalNumberOfStars:NSInteger, withFontSize size:CGFloat) ->NSAttributedString{ 


     let currentFont = UIFont(name: "<USE UR FONT HERE>", size: size)! 

     let activeStarFormat = [ NSFontAttributeName:currentFont, NSForegroundColorAttributeName: UIColor.redColor()]; 

     let inactiveStarFormat = [ NSFontAttributeName:currentFont, NSForegroundColorAttributeName: UIColor.lightGrayColor()]; 

     let starString = NSMutableAttributedString() 

     for(var i = 0; i < totalNumberOfStars; ++i){ 

      if(rating >= Float(i+1)){ 
       // This is for selected star. Change the unicode value according to the font that you use 
       starString.appendAttributedString(NSAttributedString(string: "\u{22C6} ", attributes: activeStarFormat)) 
      } 
      else if (rating > Float(i)){ 
       // This is for selected star. Change the unicode value according to the font that you use 
       starString.appendAttributedString(NSAttributedString(string: "\u{E1A1} ", attributes: activeStarFormat)) 
      } 
      else{ 
       // This is for de-selected star. Change the unicode value according to the font that you use 
       starString.appendAttributedString(NSAttributedString(string: "\u{22C6} ", attributes: inactiveStarFormat)) 
      } 
     } 

     return starString 
    } 
} 

ZASTOSOWANIE:

starLabel.attributedText = NSMutableAttributedString().starWithRating(3.5, outOfTotal: 5, withFontSize: 8.0) 
starLabelFull.attributedText = NSMutableAttributedString().starWithRating(5, outOfTotal: 5, withFontSize: 8.0) 
starLabelZero.attributedText = NSMutableAttributedString().starWithRating(0, outOfTotal: 5, withFontSize: 8.0) 
1

Swift3

https://github.com/marketplacer/Cosmos

  • zainstalować pod

    target 'TargetName' do

    pod 'Cosmos'

  • plik instalacyjny pod z tym poleceniem pod install

  • Put proste UIView w serii ujęć i podać nazwę klasy jako CosmosView i nazwę modułu Cosmos

enter image description here

Tutaj można uzyskać dostęp do atrybutów

enter image description here

0

Użyj https://github.com/hugocampossousa/HCSStarRatingView. łatwo to wdrożyć. po prostu zapisz te linie kodu. Utwórz IBOutlet HCSStarRatingView dla pliku .h utworzyć jeden ciąg do przechowywania wartości oceny.

@property (weak, nonatomic) IBOutlet HCSStarRatingView *starRatingView; 
@property (weak, nonatomic) NSString *ratingStr; 

w .m pliku zapisać te linie

self.starRatingView.maximumValue = 5; 
self.starRatingView.minimumValue = 0; 
self.starRatingView.value = 0; 
self.starRatingView.tintColor = [UIColor yellowColor]; 
self.starRatingView.allowsHalfStars = YES; 
self.starRatingView.emptyStarImage = [[UIImage imageNamed:@"heart-empty"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
self.starRatingView.filledStarImage = [[UIImage imageNamed:@"heart-full"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
[self.starRatingView addTarget:self action:@selector(didChangeValue:) forControlEvents:UIControlEventValueChanged]; 

- (IBAction)didChangeValue:(HCSStarRatingView *)sender { 
    NSLog(@"Changed rating to %.1f", sender.value); 
    ratingStr = [NSString stringWithFormat:@"%.1f",sender.value]; 
    if([hostRatingStr isEqualToString:@"-0.0"]){ 
     self.ratingLbl.text = @"0.0"; 
    }else{ 
     self.ratingLbl.text = hostRatingStr; 
    } 
} 
-2

Tak istnieje wiele bibliotek, które można wykorzystać, aby takie kontrole jak kosmosu Cosmos library for rating control

jeśli chcesz coś podobnego, który wygląda jak wykres oceny (jak ten na zdjęciu), następnie można zobaczyć to repo w github Rating graph view in iOS

enter image description here

+0

Nie rozumiem downvote .. Działa dobrze! –

Powiązane problemy