Skip to content

Commit 02d42f7

Browse files
Add overriding class method(layerClass) example.
1 parent 151bb14 commit 02d42f7

4 files changed

Lines changed: 44 additions & 3 deletions

File tree

Classes/iOS/FrameworkSupport/UIKit/JSBUIColor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
+ (UIColor *)colorWithWhite:(CGFloat)white alpha:(CGFloat)alpha;
2323
+ (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;
2424
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
25-
+ (UIColor *)colorWithCGColor:(CGColorRef)cgColor;
25+
+ (UIColor *)colorWithCGColor:(id)cgColor;
2626
+ (UIColor *)colorWithPatternImage:(UIImage *)image;
2727
+ (UIColor *)colorWithCIColor:(CIColor *)ciColor;
2828
+ (UIColor *)blackColor;
@@ -44,7 +44,7 @@
4444
- (UIColor *)initWithWhite:(CGFloat)white alpha:(CGFloat)alpha;
4545
- (UIColor *)initWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;
4646
- (UIColor *)initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
47-
- (UIColor *)initWithCGColor:(CGColorRef)cgColor;
47+
- (UIColor *)initWithCGColor:(id)cgColor;
4848
- (UIColor *)initWithPatternImage:(UIImage *)image;
4949
- (UIColor *)initWithCIColor:(CIColor *)ciColor;
5050
- (void)set;
@@ -54,7 +54,7 @@
5454
- (BOOL)getHue:(CGFloat *)hue saturation:(CGFloat *)saturation brightness:(CGFloat *)brightness alpha:(CGFloat *)alpha;
5555
- (BOOL)getRed:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha;
5656
- (UIColor *)colorWithAlphaComponent:(CGFloat)alpha;
57-
- (CGColorRef)CGColor;
57+
- (id)CGColor;
5858

5959
#pragma clang diagnostic pop
6060

Examples/UICatalog/UICatalog.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
14B5CD301875C3740019A135 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 14B5CD2F1875C3740019A135 /* AppDelegate.m */; };
7272
14B5CD321875C3740019A135 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 14B5CD311875C3740019A135 /* Images.xcassets */; };
7373
14D6C30C18793F12005C7018 /* collectionViewController.js in Resources */ = {isa = PBXBuildFile; fileRef = 14D6C30B18793F12005C7018 /* collectionViewController.js */; };
74+
14F55CFB18A1882E008B798E /* gradientViewController.js in Resources */ = {isa = PBXBuildFile; fileRef = 14F55CFA18A1882E008B798E /* gradientViewController.js */; };
7475
/* End PBXBuildFile section */
7576

7677
/* Begin PBXFileReference section */
@@ -803,6 +804,7 @@
803804
14B5CD311875C3740019A135 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
804805
14B5CD381875C3750019A135 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
805806
14D6C30B18793F12005C7018 /* collectionViewController.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = collectionViewController.js; path = js/collectionViewController.js; sourceTree = "<group>"; };
807+
14F55CFA18A1882E008B798E /* gradientViewController.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = gradientViewController.js; path = js/gradientViewController.js; sourceTree = "<group>"; };
806808
/* End PBXFileReference section */
807809

808810
/* Begin PBXFrameworksBuildPhase section */
@@ -1782,6 +1784,7 @@
17821784
14A045011877E7B1004831E8 /* webViewController.js */,
17831785
14A0450D1877E870004831E8 /* mapViewController.js */,
17841786
149ED65018A148230078236E /* gestureViewController.js */,
1787+
14F55CFA18A1882E008B798E /* gradientViewController.js */,
17851788
);
17861789
name = js;
17871790
sourceTree = "<group>";
@@ -1937,6 +1940,7 @@
19371940
14A0450E1877E870004831E8 /* mapViewController.js in Resources */,
19381941
149ED65218A1483D0078236E /* gestureViewController.js in Resources */,
19391942
14B5CD2A1875C3740019A135 /* InfoPlist.strings in Resources */,
1943+
14F55CFB18A1882E008B798E /* gradientViewController.js in Resources */,
19401944
14B5CD321875C3740019A135 /* Images.xcassets in Resources */,
19411945
);
19421946
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var GradientView = JSB.defineClass('GradientView : UIView', {
2+
initWithFrame: function(frame) {
3+
var layer = self.layer;
4+
layer.startPoint = {x: 0.0, y: 0.5};
5+
layer.endPoint = {x: 1.0, y: 0.5};
6+
7+
var colors = [];
8+
for (var deg = 0; deg <= 360; deg += 5) {
9+
var color = UIColor.colorWithHueSaturationBrightnessAlpha(1.0 * deg / 360.0, 1.0, 1.0, 1.0);
10+
colors.push(color.CGColor());
11+
}
12+
layer.colors = colors;
13+
14+
return self;
15+
}
16+
}, {
17+
layerClass: function() {
18+
return CAGradientLayer;
19+
}
20+
});
21+
22+
var GradientViewController = JSB.defineClass('GradientViewController : UIViewController', {
23+
viewDidLoad: function() {
24+
self.navigationItem.title = 'Gradient Layer';
25+
26+
var gradientView = GradientView.alloc().initWithFrame(self.view.bounds);
27+
self.view.addSubview(gradientView);
28+
}
29+
});
30+
31+
JSB.exports = GradientViewController;

Examples/UICatalog/UICatalog/js/mainViewController.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var CollectionViewController = JSB.require('collectionViewController');
55
var WebViewController = JSB.require('webViewController');
66
var MapViewController = JSB.require('mapViewController');
77
var GestureViewController = JSB.require('gestureViewController');
8+
var GradientViewController = JSB.require('gradientViewController');
89

910
var MainViewController = JSB.defineClass('MainViewController : UITableViewController', {
1011
viewDidLoad: function() {
@@ -44,6 +45,11 @@ var MainViewController = JSB.defineClass('MainViewController : UITableViewContro
4445
title: 'Gesture',
4546
explanation: 'Use of UIGestureRecognizer',
4647
viewController: GestureViewController.alloc().init()
48+
},
49+
{
50+
title: 'Gradient Layer',
51+
explanation: 'Use of CAGradientLayer',
52+
viewController: GradientViewController.alloc().init()
4753
}]
4854
},
4955
tableViewNumberOfRowsInSection: function(tableView, section) {

0 commit comments

Comments
 (0)