代码待kk封ll装的
@interface HATextView : UITextView
@property(nonatomic,copy) NSString *myPlaceholder; //文字
@property(nonatomic,strong) UIColor *myPlaceholderColor;
@end
@interface HATextView()
@property (nonatomic,weak) UILabel *placeholderLabel;
@end
@implementation HATextView
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self) {
self.backgroundColor= [UIColor clearColor];
UILabel *placeholderLabel = [[UILabel alloc]init];//添加一个占位label
placeholderLabel.font = [UIFont systemFontOfSize:14];
placeholderLabel.backgroundColor = [UIColor clearColor];
placeholderLabel.numberOfLines = 0; //设置可以输入多行文字时可以自动换行
[self addSubview:placeholderLabel];
self.placeholderLabel= placeholderLabel; //赋值保存
self.myPlaceholderColor= [UIColor lightGrayColor]; //设置占位文字默认颜色
self.font= [UIFont systemFontOfSize:14]; //设置默认的字体
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:self]; //通知:监听文字的改变
}
return self;
}
- (void)textDidChange {
self.placeholderLabel.hidden = self.hasText;
}
- (void)layoutSubviews{
[super layoutSubviews];
self.placeholderLabel.frame = CGRectMake(8, 6, 200, 16);
}
- (void)setMyPlaceholder:(NSString*)myPlaceholder{
_myPlaceholder= [myPlaceholder copy];
//设置文字
self.placeholderLabel.text = myPlaceholder;
//重新计算子控件frame
[self setNeedsLayout];
}
- (void)setMyPlaceholderColor:(UIColor*)myPlaceholderColor{
_myPlaceholderColor= myPlaceholderColor;
self.placeholderLabel.textColor= myPlaceholderColor;
}
- (void)setFont:(UIFont*)font{
[super setFont:font];
self.placeholderLabel.font= font;
//重新计算子控件frame
[self setNeedsLayout];
}
- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:UITextViewTextDidChangeNotification];
}
- (void)awakeFromNib{
[super awakeFromNib];
self.backgroundColor= [UIColor clearColor];
UILabel *placeholderLabel = [[UILabel alloc]init];//添加一个占位label
placeholderLabel.font = [UIFont systemFontOfSize:14];
placeholderLabel.backgroundColor = [UIColor clearColor];
placeholderLabel.numberOfLines = 0; //设置可以输入多行文字时可以自动换行
[self addSubview:placeholderLabel];
self.placeholderLabel= placeholderLabel; //赋值保存
self.myPlaceholderColor= [UIColor lightGrayColor]; //设置占位文字默认颜色
self.font= [UIFont systemFontOfSize:14]; //设置默认的字体
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:self]; //通知:监听文字的改变
}
阴影
self.connectView.layer.shadowOpacity = 0.4;
self.connectView.layer.shadowColor = Color16(0x575757).CGColor;
self.connectView.layer.shadowOffset = CGSizeMake(0, 4);
self.connectView.layer.cornerRadius = 5.0;
self.connectView.layer.shadowRadius = 8.0;
虚实线
CAShapeLayer *border = [CAShapeLayer layer];
border.strokeColor = isBool? CGColor(0x0E97A9):CGColor(0x999999);
border.fillColor = nil;
border.path = [UIBezierPath bezierPathWithRect:view1.layer.bounds].CGPath;
border.frame = view1.layer.bounds;
border.lineWidth = 1;
//[border setLineJoin:kCALineJoinMiter];
//border.lineCap = @"square";
border.lineDashPattern = @[@4, @2];
_shapeLayer = border;
[view1.layer addSublayer:_shapeLayer];
//// left Top corner
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.statusLabel.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(5, 5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
maskLayer.frame = self.statusLabel.bounds;
maskLayer.path = maskPath.CGPath;
self.statusLabel.layer.mask = maskLayer;
////// select Image
- (IBAction)updateImgData:(id)sender {
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"选择图片来源" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self selectImageFromCamera];
}];
UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self selectImageFromAlbum];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertVc addAction:cameraAction];
[alertVc addAction:photoAction];
[alertVc addAction:cancelAction];
[self presentViewController:alertVc animated:YES completion:nil];
}
- (void)selectImageFromCamera {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void)selectImageFromAlbum {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
#pragma mark 调用系统相册及拍照功能实现方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
UIImage * chosenImage = info[UIImagePickerControllerOriginalImage];
UIImage *currentImg = [self imageWithImageSimple:chosenImage scaledToSize:CGSizeMake(200, 120)];
NSData *imageData = UIImagePNGRepresentation(currentImg);
}
////UITextField
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{
NSString * currentString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (currentString.length>10) {
return NO;
}
return YES; // 能改变输入框的值
}
//// simpe Animate
self.animationView.transform = CGAffineTransformMakeScale(0.2, 0.2);
[UIView animateWithDuration:0.3 delay:0.02 usingSpringWithDamping:0.6 initialSpringVelocity:3 options:0 animations:^{
self.animationView.transform = CGAffineTransformMakeScale(1, 1);
} completion:nil];
[UIView animateWithDuration:0.3 animations:^{
self.animationView.transform = CGAffineTransformMakeScale(0.2, 0.2);
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
///// Spring
[UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:0.3 options:0.3 animations:^{
self.userInteractionEnabled = NO;
self.lineView.center = CGPointMake(sender.center.x, self.lineView.center.y);
} completion:^(BOOL finished) {
self.userInteractionEnabled = YES;
}];
////XWTransition XWTrasitionPractice pop
///push
[self performSegueWithIdentifier:@"pushAddRoom" sender:nil];
/// UIStoryboardSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"pushAddRoom"]) {
UIViewController *segVC = segue.destinationViewController;
if ([segVC isKindOfClass:[HACreatRoomCollection class]]) {
}
}
}