diff --git a/Classes/CustomBadge.h b/Classes/CustomBadge.h index 1f44fb9..b2fc389 100644 --- a/Classes/CustomBadge.h +++ b/Classes/CustomBadge.h @@ -55,5 +55,6 @@ + (CustomBadge*) customBadgeWithString:(NSString *)badgeString withScale:(CGFloat)scale withStyle:(BadgeStyle*)style; - (void) autoBadgeSizeWithString:(NSString *)badgeString; +- (void) changeXibViewToBadgeWithString:(NSString*)badgeString withScale:(CGFloat)scale; @end diff --git a/Classes/CustomBadge.m b/Classes/CustomBadge.m index 83cbacb..f02e403 100644 --- a/Classes/CustomBadge.m +++ b/Classes/CustomBadge.m @@ -69,6 +69,19 @@ - (id) initWithString:(NSString *)badgeString withScale:(CGFloat)scale withStyle return self; } +// Use this method if you want to change UIView from Xib to BadgeView. +- (void) changeXibViewToBadgeWithString:(NSString*)badgeString withScale:(CGFloat)scale{ + + self.contentScaleFactor = [[UIScreen mainScreen] scale]; + self.backgroundColor = [UIColor clearColor]; + self.badgeText = badgeString; + self.badgeStyle = [BadgeStyle defaultStyle]; + self.badgeCornerRoundness = 0.4; + self.badgeScaleFactor = scale; + [self autoBadgeSizeWithString:badgeString]; + +} + // Use this method if you want to change the badge text after the first rendering - (void) autoBadgeSizeWithString:(NSString *)badgeString diff --git a/Classes/CustomBadgeViewController.h b/Classes/CustomBadgeViewController.h index e787b40..29523e5 100644 --- a/Classes/CustomBadgeViewController.h +++ b/Classes/CustomBadgeViewController.h @@ -34,10 +34,11 @@ #import - +#import "CustomBadge.h" @interface CustomBadgeViewController : UIViewController { } +@property (weak, nonatomic) IBOutlet CustomBadge *badgeViewFromXIB; @end diff --git a/Classes/CustomBadgeViewController.m b/Classes/CustomBadgeViewController.m index 8d854e8..cca5f71 100644 --- a/Classes/CustomBadgeViewController.m +++ b/Classes/CustomBadgeViewController.m @@ -33,7 +33,6 @@ of this software and associated documentation files (the "Software"), to deal */ #import "CustomBadgeViewController.h" -#import "CustomBadge.h" @implementation CustomBadgeViewController @@ -119,6 +118,8 @@ - (void) viewDidLoad [self.view addSubview:badge]; } + [_badgeViewFromXIB changeXibViewToBadgeWithString:@"9" withScale:1.0]; + } diff --git a/CustomBadge.xcodeproj/project.xcworkspace/xcuserdata/lichunxiao.xcuserdatad/UserInterfaceState.xcuserstate b/CustomBadge.xcodeproj/project.xcworkspace/xcuserdata/lichunxiao.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..62841b8 Binary files /dev/null and b/CustomBadge.xcodeproj/project.xcworkspace/xcuserdata/lichunxiao.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/CustomBadge.xcodeproj/xcuserdata/lichunxiao.xcuserdatad/xcschemes/CustomBadge.xcscheme b/CustomBadge.xcodeproj/xcuserdata/lichunxiao.xcuserdatad/xcschemes/CustomBadge.xcscheme new file mode 100644 index 0000000..dd1d870 --- /dev/null +++ b/CustomBadge.xcodeproj/xcuserdata/lichunxiao.xcuserdatad/xcschemes/CustomBadge.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CustomBadge.xcodeproj/xcuserdata/lichunxiao.xcuserdatad/xcschemes/xcschememanagement.plist b/CustomBadge.xcodeproj/xcuserdata/lichunxiao.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..3d5e075 --- /dev/null +++ b/CustomBadge.xcodeproj/xcuserdata/lichunxiao.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + CustomBadge.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 1D6058900D05DD3D006BFB54 + + primary + + + + + diff --git a/CustomBadgeViewController.xib b/CustomBadgeViewController.xib index d207777..4b448ed 100644 --- a/CustomBadgeViewController.xib +++ b/CustomBadgeViewController.xib @@ -1,34 +1,25 @@ - + - 1056 - 10J869 - 823 - 1038.35 - 461.00 + 1808 + 14E46 + 7706 + 1348.17 + 758.70 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 132 + 7703 - - YES - - - - YES + + IBProxyObject + IBUILabel + IBUIView + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - YES - - YES - - - YES - - - - YES + + + IBFilesOwner IBCocoaTouchFramework @@ -40,8 +31,55 @@ 274 - {320, 460} + + + + 274 + {{148, 427}, {25, 25}} + + + + + 3 + MQA + + IBCocoaTouchFramework + + + + 292 + {{53, 405}, {214, 21}} + + + + {251, 251} + NO + 7 + NO + IBCocoaTouchFramework + Change UIView from XIB to BadgeView + + + 0 + 1 + + 1 + 0 + 10 + + + HelveticaNeue + 10 + 16 + + NO + YES + + + {{0, 20}, {320, 460}} + + 3 MC43NQA @@ -51,12 +89,15 @@ NO + + IBUISimulatedFreeformSizeMetricsSentinel + Freeform + IBCocoaTouchFramework - + - - YES + view @@ -65,13 +106,20 @@ 7 - + + + badgeViewFromXIB + + + + 11 + + - - YES + 0 - + @@ -89,158 +137,96 @@ 6 - - YES - + + + + - - - - YES - - YES - -1.CustomClassName - -2.CustomClassName - 6.IBEditorWindowLastContentRect - 6.IBPluginDependency - - - YES - CustomBadgeViewController - UIResponder - {{239, 654}, {320, 480}} - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - YES - - - YES - + + 9 + + + + + 10 + + + + + + CustomBadgeViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + CustomBadge + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + - - YES - - - YES - - + - 8 + 11 - - YES + - CustomBadgeViewController - UIViewController + CustomBadge + UIView IBProjectSource - Classes/CustomBadgeViewController.h - - - - - YES - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSError.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSFileManager.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueCoding.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueObserving.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyedArchiver.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSObject.h + ../Classes/CustomBadge.h - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSRunLoop.h + CustomBadgeViewController + UIViewController + + badgeViewFromXIB + CustomBadge - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSThread.h + + badgeViewFromXIB + + badgeViewFromXIB + CustomBadge + - - - NSObject - IBFrameworkSource - Foundation.framework/Headers/NSURL.h + IBProjectSource + ../Classes/CustomBadgeViewController.h + + - NSObject + UIGestureRecognizer + NSObject IBFrameworkSource - Foundation.framework/Headers/NSURLConnection.h + UIKit.framework/Headers/UIGestureRecognizer.h - NSObject + UILabel + UIView IBFrameworkSource - UIKit.framework/Headers/UIAccessibility.h + UIKit.framework/Headers/UILabel.h - NSObject + UIResponder + NSObject - IBFrameworkSource - UIKit.framework/Headers/UINibLoading.h - - - - NSObject - IBFrameworkSource UIKit.framework/Headers/UIResponder.h - - UIResponder - NSObject - - UISearchBar UIView @@ -257,20 +243,6 @@ UIKit.framework/Headers/UISearchDisplayController.h - - UIView - - IBFrameworkSource - UIKit.framework/Headers/UIPrintFormatter.h - - - - UIView - - IBFrameworkSource - UIKit.framework/Headers/UITextField.h - - UIView UIResponder @@ -279,34 +251,6 @@ UIKit.framework/Headers/UIView.h - - UIViewController - - IBFrameworkSource - UIKit.framework/Headers/UINavigationController.h - - - - UIViewController - - IBFrameworkSource - UIKit.framework/Headers/UIPopoverController.h - - - - UIViewController - - IBFrameworkSource - UIKit.framework/Headers/UISplitViewController.h - - - - UIViewController - - IBFrameworkSource - UIKit.framework/Headers/UITabBarController.h - - UIViewController UIResponder @@ -315,21 +259,16 @@ UIKit.framework/Headers/UIViewController.h - + 0 IBCocoaTouchFramework - - com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - - + NO com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 - + YES - CustomBadge.xcodeproj 3 - 132