Giter VIP home page Giter VIP logo

pdrating's Introduction

RatingView (PDRatingView)

RatingView lets you display an average rating and, optionally, collect a user's rating submission on items in your Xamarin.iOS application.

  • Custom rating images.
  • Custom rating scale.
  • Transparent background for composing.

Examples

You can use whatever images you want and whatever scale size you need. Many people use five stars.

Five star rating scale

Others have something else entirely. Perhaps you want a 10-tomato rating.

Ten tomato rating scale

Whatever you need, you give it a rectangle to fit into and it will resize things accordingly.

Six moustaches rating scale

Ratings displays are kept minimal. If you need to compose your ratings view into something else, it will overlay it just fine.

Star rating on a custom background

Usage

In any code-based UIView or UIViewController, you can add a PDRatingView to the displayed just like any other view.

using PatridgeDev;
...

PDRatingView ratingView;
public override void ViewDidLoad() {
    
    // Gather up the images to be used.
    RatingConfig ratingConfig = new RatingConfig(
        emptyImage: UIImage.FromBundle("empty"),
        filledImage: UIImage.FromBundle("filled"),
        chosenImage: UIImage.FromBundle("chosen")
    );
    
    // Create the view.
    decimal averageRating = 3.25m;
    ratingView = new PDRatingView(new CGRect(0f, 0f, View.Bounds.Width, 125f), ratingConfig, averageRating);
    
    // [Optional] Do something when the user selects a rating.
    ratingView.RatingChosen += (sender, e) => {
        (new UIAlertView("Rated!", e.Rating.ToString() + " stars", null, "Ok")).Show();
    };
    
    // [Required] Add the view to the 
    View.Add(ratingView);
}

Other Configurations Options

Between-item whitespace

Need some space between your rating items? Just set the ItemPadding in the RatingConfig object used to build the PDRatingView.

// Put a little space between the rating items.
ratingConfig.ItemPadding = 5f;

Read-only (no user rating input)

If you are showing a rating without any intention of collecting a rating from the user, you can keep the rating view from taking any user input with the default iOS setting. As a result, this will keep it from ever triggering a RatingChosen event.

// Only display the rating; don't allow user rating.
ratingView.UserInteractionEnabled = false;

Different rating scale size

Say you need users to rate things on a scale to ten. That can be changed in the RatingConfig object used to build the PDRatingView. The default is a 5-item scale of ratings.

// Allow rating on a scale of 1 to 10.
ratingConfig.ScaleSize = 10;

Rounding of ratings to whole or half stars

If you want average ratings to display in half- or whole-star increments, that isn't currently built in to the PDRatingView system directly, but you can very easily use .NET to round appropriately before setting the view's AverageRating to reproduce the same result.

decimal rating = 3.58m;
decimal halfRoundedRating = Math.Round(rating * 2m, MidpointRounding.AwayFromZero) / 2m;
decimal wholeRoundedRating = Math.Round(rating, MidpointRounding.AwayFromZero);
StarRating.AverageRating = wholeRoundedRating;

pdrating's People

Contributors

patridge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pdrating's Issues

Xamarin Components store will be shut down soon.

Hi develop team,

Microsoft has sent an email to me. By this email, Microsoft informs that Xamarin Component store will be shut down on May 15, 2018 and they suggest reference all libraries I used to NuGet instead of Xamarin Component store. But this component is not available on NuGet now. Please check and upload the current version to NuGet before Xamarin Component store is shut down completely.

Thank you so much and have a nice day.

PDRatingView don't work in UIView from StoryBoard

Hello Adam,

Unfortunately the PDRating component don't work as i want it from an UIView in the Storyboard.

for example im in mine ViewController and this ViewController has an UIView RatingViewHandler. I Add mine PDRatingView to this RatingViewHandler and it shows the stars but i can't change the values. But if i add the PDRatingView to the ViewController with View.Add(ratingView) everything works. Maybe i forgot something and u could help me out here.

Thanks in adavance.

public partial class ViewController : UIViewController
    {   

        public ViewController (IntPtr handle) : base (handle)
        {
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            RatingViewHolder.UserInteractionEnabled = true;

            var ratingConfig = new RatingConfig(emptyImage: UIImage.FromBundle("empty"),
                filledImage: UIImage.FromBundle("filled"),
                chosenImage: UIImage.FromBundle("chosen"));

            var ratingView = new PDRatingView(new CGRect(30, 10, RatingViewHolder.Frame.Width - 60, RatingViewHolder.Frame.Height - 20),ratingConfig);
            ratingView.RatingChosen += delegate { (new UIAlertView("Rated!", ratingView.ChosenRating.ToString() , null, "Ok")).Show(); };


            RatingViewHolder.Add (ratingView);

        }
}

Logo contribution

Hello, I designed a logo for PDRating. I wanted to emphasize the '' rating '' feature by using the initials of the app and a star icon. If you like it, I will send you a pr. Or If you have another logo idea, you can tell me.

rating

Readmefile view;

view

Handling RTL Direction

rating should be from right to left in case of the app is in arabic or any rtl language

PDRatingView#ItemPadding

Hi there,

I'm using PDRating in my Xamarin app, and it saved me quite some time. Thank you! However, I am having one issue:

  • The ItemPadding property (which is mentioned on the Github project page), is not available
  • Maybe related to this problem, but not sure: The namespace PatridgeDev is not available, instead I had to use PDRatingSample, which seems a little odd

Am I doing something wrong? Checked in my Xamarin project, I am using PDReview 2.0.1 which seems to be the current one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.