Inital badge project created with example #29

Closed
wants to merge 18 commits into
from

Projects

None yet

4 participants

@rogchap
rogchap commented Aug 3, 2011

This is only an early version of a badge view using QuartzCore.
Does not have a badge "gloss" yet and also not yet documented.

Challenges:

  • getting the right badge size for the font used; perhaps we should use a set font with a scale factor instead of allowing the user to change the font??
  • the drop shadow is clipped when using a smaller font; need to add more padding to the view - DONE
@jverkoey

Let's not provide so many initializers for this view. It is common practice to allocate and initialize a view only with the frame to start, after which modifications are made to the view's presentation style (consider UILabel as a good example).

When documenting the font property we should ensure that we make clear what the default font type is. It is not immediately obvious to me whether the font is bold or not, for example.

Done...but still more documentation required.

@jverkoey

Don't automatically update the size of the label here. We should try to keep the number of side effects to a minimum in property methods. A call to [self setNeedsLayout] should be sufficient here. Leave it up to the dev using this view to call sizeToFit after modifying the view's properties.

Done... your right; that feels much better, and I've included an example where you set your own frame width and height.

@jverkoey

It might be important to consider floorfing these values to ensure that the text is on an integral bound, otherwise it might be blurry.

Done.

@jverkoey

Consider implementing - (CGSize)sizeThatFits:(CGRect)size instead because it is ultimately what sizeToFit uses to determine the correct size.

I should get a slapped wrist for that one! ;)

@jverkoey

Why did you use setNeedsDisplay instead of setNeedsLayout?

Because I'm not overriding -layoutSubviews and -setNeedsDisplay will call -drawRect: when the frame updates.

Owner

Ah right, of course. Silly me forgot that you were custom drawing this view.

Cool :)

By custom drawing this view should mean that performance is way better than laying out subviews and maintains the customizable aspect without the need for images.

Owner

Which is awesome :) that reminds me, I have a new grab bag task to write up...

@bmeurer
bmeurer commented Aug 14, 2011

Shouldn't -setText: invoke -setNeedsLayout rather than -setNeedsDisplay?

@rogchap
rogchap commented Aug 14, 2011

No, as it's not doing a sub layout as everything is manually drawn onto the view. -setNeedsDisplay will invoke -drawRect which is what is required.

There is a previous comment on this.

Sent from my iPhone

On 14 Aug 2011, at 16:39, bmeurerreply@reply.github.com wrote:

Shouldn't -setText: invoke -setNeedsLayout rather than -setNeedsDisplay?

Reply to this email directly or view it on GitHub:
#29 (comment)

@bmeurer
bmeurer commented Aug 14, 2011

-setText: is different, because the size depends on the actual text in your -sizeThatFits: implementation, so relayouting makes sense when text changes.

@rogchap
rogchap commented Aug 14, 2011

Even the text is drawn within -drawRect, therefore I want -drawRect to be called which -setNeedsDisplay does. Only if text was being added via UILabel in overriding the -layout method would -setNeedsLayout be required.

That's my understanding of it anyway...will happily be corrected :)

Sent from my iPhone

On 14 Aug 2011, at 20:17, bmeurerreply@reply.github.com wrote:

-setText: is different, because the size depends on the actual text in your -sizeThatFits: implementation, so relayouting makes sense when text changes.

Reply to this email directly or view it on GitHub:
#29 (comment)

@bmeurer
bmeurer commented Aug 14, 2011

I'm not an expert in the UIView programming stuff, but my understanding is that -setNeedsLayout triggers layout, which in turn triggers redisplay, and whenever something is about to change the (preferred) size of an UIView it should invoke -setNeedsLayout.

But as said, that's just how I read the documentation.

@bmeurer
bmeurer commented Aug 14, 2011

Forget about that. I stand corrected. -setNeedsLayout is only for subviews of the receiver.

@rogchap
rogchap commented Aug 17, 2011

This should be in a decent state now; with documentation, and rebased with current master (0.6.1). Let me know if there are any changes required?

@jverkoey
Owner

Will do! I'm going to play with this a bit today I think after I write unit tests for the Nimbus Models.

@alias1
alias1 commented Sep 29, 2011

Just wondering whether this is pretty much completed now?

@rogchap
rogchap commented Sep 30, 2011

This should be ready :)

@jverkoey jverkoey referenced this pull request Oct 25, 2011
Closed

Build a Badge View #27

@jverkoey jverkoey added a commit that closed this pull request Jun 20, 2012
@jverkoey Merge branch 'rogchap-badge'
Closes #29.
70ea759
@jverkoey jverkoey closed this in 70ea759 Jun 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment