【发布时间】:2018-09-18 21:27:39
【问题描述】:
所以我无法访问 UISubview 类中的方法。我没有通过代码进行初始化,但我添加了一个 UIView 并将类设置为IVVerticalProgress。
但是当我尝试打电话时
[_weakIBOutlet setProgressValue:50];
什么都没有发生,我没有打印出来。但是,如果我初始化对象,它工作得很好。但不更新视图。
这里有什么帮助吗? :-)
标题
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class IVVerticalProgress;
IB_DESIGNABLE
@interface IVVerticalProgress : UIView {
UIView *gauge;
CGFloat initialHeight;
}
@property (nonatomic) IBInspectable CGFloat cornerRadius, borderWidth;
@property (nonatomic) IBInspectable UIColor *fillColor, *borderColor;
@property (nonatomic) IBInspectable double animationDuration;
-(void)setProgressValue:(CGFloat)value;
@end
身体
#import "IVVerticalProgress.h"
@implementation IVVerticalProgress
-(void)drawRect:(CGRect)rect {
self.layer.backgroundColor = self.fillColor.CGColor;
self.layer.borderColor = self.borderColor.CGColor;
self.layer.borderWidth = self.borderWidth;
self.layer.cornerRadius = self.cornerRadius;
self.clipsToBounds = YES;
gauge = [[UIView alloc] initWithFrame:CGRectMake(0,0,rect.size.width,0)];
[gauge setBackgroundColor:[UIColor redColor]];
[self addSubview:gauge];
}
- (id)sharedInit {
self.backgroundColor = [UIColor clearColor];
self.layer.transform = CATransform3DMakeRotation(M_PI, 0.0, 0.0, 1.0);
initialHeight = self.layer.frame.size.height;
return self;
}
- (id)initWithFrame: (CGRect)frame {
self = [super initWithFrame: frame];
if (self) {
self = [self sharedInit];
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self = [self sharedInit];
}
return self;
}
-(void)setProgressValue:(CGFloat)value {
if (value < 0)
value = 0;
if (value > 100)
value = 100;
CGFloat percentageHeight = (initialHeight / 100) * value;
[gauge setFrame:CGRectMake(gauge.frame.origin.x,
gauge.frame.origin.y,
gauge.frame.size.width,
percentageHeight)];
NSLog(@"%f",value);
}
@end
【问题讨论】:
-
您是否再次检查了它的调用并为我打印了价值
标签: objective-c xcode methods