Giter Club home page Giter Club logo

fxlabel's People

Contributors

nicklockwood avatar wenchaod avatar

Stargazers

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

Watchers

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

fxlabel's Issues

FXLabel does not support attributedStrings ?

I love this pod, but unfortunately I cannot get it to work with attributed strings. :(
This is what i want to do:
FXLabel *myLabel = [[FXLabel alloc] init];

UIFont *fnt = [UIFont fontWithName:@"Helvetica" size:20.0];

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"GGG®GGG"
attributes:@{NSFontAttributeName: [fnt fontWithSize:20]}];
[attributedString setAttributes:@{NSFontAttributeName : [fnt fontWithSize:10]
, NSBaselineOffsetAttributeName : @10} range:NSMakeRange(3, 1)];

myLabel.attributedText = attributedString;

FXLabel Animate Font Size

Hi Nick,

I actually want to animate font size between two values but UIView animation does not work on UILabel font size.

Start Font Size= 20 pts
End Font Size = 100 pts

In animation it sets 100pts at once not animate and gradually increase. I actually want to gradually increase the font size.

Can you help how to achieve or can FXLabel help to achieve.

Thanks,

1.5.4 has infinite loop with iOS 7 only deployment target.

Line 265 - 270

if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000

...
while (size.width > width && fontSize >= minFontSize)
{
size.width = [self sizeWithAttributes:@{NSFontAttributeName: [font fontWithSize:fontSize]}].width;
if (actualFontSize) *actualFontSize = fontSize;
fontSize = MAX(minFontSize, fontSize - 1);
}
...
The fontSize is always greater or equal then minFontSize because fontSize takes MAX(minFontSize, fontSize -1).

It happens to me. :(

Have the glow/shaddow inherit the gradient

I'm not sure if this is possible with your drawing code or not, but I'd like to have the glow on the text match the gradient used on it. I have tried using images of the text, applying a blur and setting the image behind the text but I figured using something like FXLabel would be a better way of handling this, especially when editing the text.

Is this possible with FXLabel, either now or in the future?

Major optimization

Hi,

Is there are reason for using drawAtPoint: withFont: instead of just sizeWithFont: in FXLabel_sizeWithFont: ?

Because the latter saves the need to use a context, prevents pointless drawing and a lot of warnings I got during run time prior to changing it. Am I missing anything?

Cheers,
-Eran

New Line Characters on arm64?

Hi, it seems like only on arm64 devices, and not on the arm64 simulator, '\n's are never correctly interpreted when sizing or counting lines. On all other devices I've tried and simulators, FXLabels that I include '\n' on are always sized correctly, but on my 5S they are cut off with a ellipsis.

Example string being "Alarm was\n12 hours ago", is truncated to "Alarm..." or "Alarm was..." instead of a two line label. Any ideas?

Thanks for all the work Nick, I really appreciate the Open Source work you've done.

Tj-

'adjustsFontSizeToFitWidth' doesn't seem to work ...

Font size isn't adjusted with long text. It just gets trimmed. Tried messing with lineBreakMode but with no success...

FXLabel *lblValue           = [[FXLabel alloc] initWithFrame: CGRectMake(14, 129, 138, 38)];
lblValue.font               = [UIFont systemFontOfSize: 33];
lblValue.gradientColors     = @[RGBA(249, 249, 249, 1.0),
                                             RGBA(216, 216, 216, 1.0)];
lblValue.backgroundColor    = [UIColor clearColor];
lblValue.adjustsFontSizeToFitWidth = YES;
lblValue.textAlignment      = NSTextAlignmentCenter;
lblValue.text               = @"6666444";

size to fit fails with numberOfLines = 2 and lineSpacing != 1

ios 8+, auto layout

label setup:

[label setFont: customFont ];
label.characterSpacing = 0.012500000000000001; //calculated automatically ;)
label.lineSpacing = 1.2;
label.numberOfLines = 2;
label.lineBreakMode = NSLineBreakByWordWrapping;
[label sizeToFit];

the label doesn't resize correctly if has the second line, works correctly with lineSpacing = 0

crash on FXLabel 1.3.2 version

after updating I have a crash FXLabel.m , line 388 [colors addObject:(__bridge id)colorRef];. Added FXLabel as git submodule (added FXLabel.m and FXLabel.h files to the project). Crash is only on the device iPhone 4, iOS 5.1 (9B176). Xcode Version 4.3.1 (4E1019). On 5.1 simulator there is no problem. If revert to FXLabel 1.3.1 everything works.

if set lineSpacing, sizeThatFits not support chinese characters

self.titleLabel = [[FXLabel alloc] initWithFrame:CGRectMake(9, 7, 100, font.lineHeight)];
self.titleLabel.numberOfLines = 0;
self.titleLabel.font = font;
self.titleLabel.backgroundColor = [UIColor clearColor];
self.titleLabel.textColor = [UIColor whiteColor];
self.titleLabel.shadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
self.titleLabel.shadowOffset = CGSizeMake(0, 1);
self.titleLabel.shadowBlur = 1;
self.titleLabel.lineSpacing = 0.27;
self.titleLabel.text = @"如果是中文,就不会换行了";

1.5.3 FXLabel sometimes ignores the UILabel textColor property

Ive just updated to 1.5.3 and there is a bug where FXLabel sometimes ignores the value of the textColor property of its UILabel super type.

I worked around by setting the gradientStartColor to the same value as textColor, but its not ideal.

This bug affects only FXLabels that use no FXLabel properties. FXLabels that use some FXLabel properties apply the textColor correctly

Crash in FXLabel_linesWithFont:constrainedToSize:lineBreakMode:lineSpacing:allowOrphans:

Not sure about the cause yet but just received multiple crash reports with the following trace:

Incident Identifier: [TODO]
CrashReporter Key:   [TODO]
Hardware Model:      iPad3,6
Process:         Zodio [7432]
Path:            /Users/USER/Zodio.app/Zodio
Identifier:      com.zodio.Zodio
Version:         323
Code Type:       ARM
Parent Process:  launchd [1]

Date/Time:       2556-06-06 14:06:58 +0000
OS Version:      iPhone OS 6.1.3 (10B329)
Report Version:  104

Exception Type:  SIGABRT
Exception Codes: #0 at 0x3998c350
Crashed Thread:  0

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

Last Exception Backtrace:
0   CoreFoundation                      0x315fe3e7 __exceptionPreprocess + 163
1   libobjc.A.dylib                     0x39498963 objc_exception_throw + 31
2   CoreFoundation                      0x31548c6d -[__NSArrayM insertObject:atIndex:] + 777
3   Zodio                               0x003c0329 -[NSString(FXLabelDrawing) FXLabel_linesWithFont:constrainedToSize:lineBreakMode:lineSpacing:allowOrphans:] + 1121
4   Zodio                               0x003c048f -[NSString(FXLabelDrawing) sizeWithFont:constrainedToSize:lineBreakMode:lineSpacing:allowOrphans:] + 111
5   Zodio                               0x003c11b3 -[FXLabel FXLabel_sizeThatFits:actualFontSize:] + 479
6   Zodio                               0x003c130b -[FXLabel sizeThatFits:] + 107
7   UIKit                               0x33435f33 -[UIView(Geometry) sizeToFit] + 119
8   Zodio                               0x0012f635 -[UIViewController(ErrorHandling) showFullscreenErrorWithMessage:buttonTitle:retryMethod:inRect:] (UIViewController+ErrorHandling.m:692)
9   Zodio                               0x002c55bf -[ZUserBookmarksViewController loadData] (ZUserBookmarksViewController.m:162)
10  Zodio                               0x0018e3fd -[JGBusinessListViewController viewDidLoad] (JGBusinessListViewController.m:58)
11  Zodio                               0x002c4693 -[ZUserBookmarksViewController viewDidLoad] (ZUserBookmarksViewController.m:50)
12  UIKit                               0x3342c579 -[UIViewController loadViewIfRequired] + 365
13  UIKit                               0x334811f7 -[UIViewController contentScrollView] + 27
14  UIKit                               0x3348113d -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 29
15  UIKit                               0x33481021 -[UINavigationController _layoutViewController:] + 33
16  UIKit                               0x33480f4d -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 273
17  UIKit                               0x33480699 -[UINavigationController _startTransition:fromViewController:toViewController:] + 65
18  UIKit                               0x33480581 -[UINavigationController _startDeferredTransitionIfNeeded:] + 325
19  UIKit                               0x33451561 -[UILayoutContainerView layoutSubviews] + 181
20  UIKit                               0x334108c7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 259
21  QuartzCore                          0x331bc513 -[CALayer layoutSublayers] + 215
22  QuartzCore                          0x331bc0b5 CA::Layer::layout_if_needed(CA::Transaction*) + 461
23  QuartzCore                          0x331bcfd9 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 17
24  QuartzCore                          0x331bc9c3 CA::Context::commit_transaction(CA::Transaction*) + 239
25  QuartzCore                          0x331bc7d5 CA::Transaction::commit() + 317
26  QuartzCore                          0x331bc639 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 61
27  CoreFoundation                      0x315d3941 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 21
28  CoreFoundation                      0x315d1c39 __CFRunLoopDoObservers + 277
29  CoreFoundation                      0x315d1f93 __CFRunLoopRun + 747
30  CoreFoundation                      0x3154523d CFRunLoopRunSpecific + 357
31  CoreFoundation                      0x315450c9 CFRunLoopRunInMode + 105
32  GraphicsServices                    0x3510033b GSEventRunModal + 75
33  UIKit                               0x334612b9 UIApplicationMain + 1121
34  Zodio                               0x000f780b main (main.m:16)
35  Zodio                               0x000f77c0 start + 40

Stroke with custom width and color

hi, i am using your class in a project and i wish to add a stroke,
trying to add the stroke at the end of your drawrect code seems to fail
can you please add stroke functionality?

here is an example for the code that fails me

if (self.strokeColor != nil && self.strokeWidth > 0)
{

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);
    CGContextSetTextDrawingMode(context, kCGTextFill);

    // Draw the text without an outline
    [super drawTextInRect:rect];

    CGImageRef alphaMask = NULL;

    // Create a mask from the text (with the gradient)
    alphaMask = CGBitmapContextCreateImage(context);

    // Outline width
    CGContextSetLineWidth(context, strokeWidth);
    CGContextSetLineJoin(context, kCGLineJoinRound);

    // Set the drawing method to stroke
    CGContextSetTextDrawingMode(context, kCGTextStroke);

    // Outline color
    self.textColor = self.strokeColor;

    [self.text drawInRect:textRect withFont:font lineBreakMode:self.lineBreakMode alignment:self.textAlignment];


    //[super drawTextInRect:CGRectMake(rect.origin.x, rect.origin.y+1, rect.size.width, rect.size.height)];

    // Draw the saved image over the outline
    // and invert everything because CoreGraphics works with an inverted coordinate system
    CGContextTranslateCTM(context, 0, textRect.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextDrawImage(context, textRect, alphaMask);

    // Clean up because ARC doesnt handle CG
    CGImageRelease(alphaMask);
}

Deprecations in iOS 7

drawAtPoint:withFont: etc. are all deprecated in iOS 7 and need to be replaced with sizeWithAttributes: etc.

Crash when text is long Chinese or long words

_label.numberOfLines = 0;
_label.lineBreakMode = UILineBreakModeWordWrap;
//for example: _label.frame.size.width = 100px

//crash when long Chinese
_label.text = @"这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字";

//or crash when long words
_label.text = @"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

bug when gradientcolors + text insets

These is a bug when use gradient colors and text insets.

here is the solution

start at line 1022 in FXLabel.m

if (hasGradient) {
        CGContextSaveGState(context);
        // bug --> CGContextTranslateCTM(context, 0, contentRect.size.height);
        CGContextTranslateCTM(context, 0, self.bounds.size.height);
        CGContextScaleCTM(context, 1.0, -1.0);
        // bug --> CGContextClipToMask(context, contentRect, alphaMask);
        CGContextClipToMask(context, self.bounds, alphaMask);

Sorry for my poor english.
:)

Update cocoa pods?

I'm using the FXLabel pod (version 1.3.7) and it looks like its missing some of the latest additions, namely the characterSpacing and lineSpacing properties. Is it possible to push the latest version to cocoa pods?

Using initWithFrame

When using initWithFrame the gradient effect and inner shadow doesn't seem to work properly. Is there a way around this? Basically the inner shadow and gradient is being applied to the frame instead of the label within the frame.

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.