awakefromnib有一个字符串s,查找字符串s是否在字符串中t,如果有返回重复的个数,C语言或者Objective-C变成

awakefromnib  时间:2021-07-05  阅读:()

如何在UITextView中添加默认文字

在UITextField中自带placeholder属性,可以用于提示输入框信息。

但是UITextView并不具备此功能 介绍两种方法来实现: 第一种: 初始化UITextView //首先定义UITextView UITextView *textView = [[UITextView alloc] init]; textView.font = [UIFont systemFontOfSize:14]; textView.frame =CGRectMake(10, 0, cell.contentView.bounds.size.width-20, side); textView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; textView.backgroundColor = [UIColor whiteColor]; [cell.contentView addSubview:textView]; textView.hidden = NO; textView.delegate = self; //其次在UITextView上面覆盖个UILable,UILable设置为全局变量。

uilabel.frame =CGRectMake(17, 8, cell.contentView.bounds.size.width - side+10, 20); uilabel.text = @"请填写审批意见..."; uilabel.enabled = NO;//lable必须设置为不可用 uilabel.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:uilabel]; 实现UITextView的代理 -(void)textViewDidChange:(UITextView *)textView { self.examineText = textView.text; if (textView.text.length == 0) { uilabel.text = @"请填写审批意见..."; }else{ uilabel.text = @""; } } 第二种: UITextView 实现 placeholder 及隐藏键盘 #import @interface UIPlaceHolderTextView : UITextView { NSString *placeholder; UIColor *placeholderColor; @private UILabel *placeHolderLabel; } @property(nonatomic, retain) UILabel *placeHolderLabel; @property(nonatomic, retain) NSString *placeholder; @property(nonatomic, retain) UIColor *placeholderColor; -(void)textChanged:(NSNotification*)notification; @end #import "UIPlaceHolderTextView.h" @implementation UIPlaceHolderTextView @synthesize placeHolderLabel; @synthesize placeholder; @synthesize placeholderColor; - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [placeHolderLabel release]; placeHolderLabel = nil; [placeholderColor release]; placeholderColor = nil; [placeholder release]; placeholder = nil; [super dealloc]; } - (void)awakeFromNib { [super awakeFromNib]; [self setPlaceholder:@""]; [self setPlaceholderColor:[UIColor lightGrayColor]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil]; } - (id)initWithFrame:(CGRect)frame { if( (self = [super initWithFrame:frame]) ) { [self setPlaceholder:@""]; [self setPlaceholderColor:[UIColor lightGrayColor]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil]; } return self; } - (void)textChanged:(NSNotification *)notification { if([[self placeholder] length] == 0) { return; } if([[self text] length] == 0) { [[self viewWithTag:999] setAlpha:1]; } else { [[self viewWithTag:999] setAlpha:0]; } } - (void)setText:(NSString *)text { [super setText:text]; [self textChanged:nil]; } - (void)drawRect:(CGRect)rect { if( [[self placeholder] length] > 0 ) { if ( placeHolderLabel == nil ) { placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(8,8,self.bounds.size.width - 16,0)]; placeHolderLabel.lineBreakMode = UILineBreakModeWordWrap; placeHolderLabel.numberOfLines = 0; placeHolderLabel.font = self.font; placeHolderLabel.backgroundColor = [UIColor clearColor]; placeHolderLabel.textColor = self.placeholderColor; placeHolderLabel.alpha = 0; placeHolderLabel.tag = 999; [self addSubview:placeHolderLabel]; } placeHolderLabel.text = self.placeholder; [placeHolderLabel sizeToFit]; [self sendSubviewToBack:placeHolderLabel]; } if( [[self text] length] == 0 && [[self placeholder] length] > 0 ) { [[self viewWithTag:999] setAlpha:1]; } [super drawRect:rect]; } @end //隐藏键盘,实现UITextViewDelegate -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text { if ([text isEqualToString:@" "]) { [m_textView resignFirstResponder]; return NO; } return YES; }

storyboard中定义的view的坐标和大小,用代码改变大小时,是不是改变不了

1. 建一个 UIView的子类(MyView.h/MyView.m) 2. 建一个 View类型的XIB 3. 把xib的file‘s owner设为MyView 4. 在.h文件里加上 @property (nonatomic, retain) IBOutlet UIView *contentView;   5.绑定xib里的根view到.h里的 contentView 6.在.m里加上   - (void)awakeFromNib { NSLog(@"awake from nib"); [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil]; [self addSubview:self.contentView]; }   ok了。

storyboard里用的时候把UIView的类名改为MyView就可以。

xib和.h可以互相绑定子outlet什么的。

关于控制view的UIView.m类的请教

如果你是用initwithframe创建的view,你就自己写个initwithframe。

- (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self;}如果你是用interface builder拽的view,用下面的肯定可以-(void)awakeFromNib{}

有一个字符串s,查找字符串s是否在字符串中t,如果有返回重复的个数,C语言或者Objective-C变成

返回值如果为0 说明没找到 #import "find.h" @implementation find - (void)awakeFromNib { NSString *str1 = @"tststststssststststst"; NSString *str2 = @"s"; int iCount = [self findTheString:str2 FromString:str1]; NSLog(@"%d",iCount); } - (int)findTheString:(NSString *)str1 FromString:(NSString *)str2 { NSArray *array = [ponentsSeparatedByString:str1]; return [array count] - 1; } @end

妮妮云(43元/月 ) 香港 8核8G 43元/月 美国 8核8G

妮妮云的来历妮妮云是 789 陈总 张总 三方共同投资建立的网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑妮妮云的市场定位妮妮云主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。妮妮云的售后保证妮妮云退款 通过于合作商的友好协商,云服务器提供2天内全额退款,超过2天不退款 物...

ShockHosting日本机房VPS测试点评

这个月11号ShockHosting发了个新上日本东京机房的邮件,并且表示其他机房可以申请转移到日本,刚好赵容手里有个美国的也没数据就发工单申请新开了一个,这里做个简单的测试,方便大家参考。ShockHosting成立于2013年,目前提供的VPS主机可以选择11个数据中心,包括美国洛杉矶、芝加哥、达拉斯、杰克逊维尔、新泽西、澳大利亚、新加坡、日本、荷兰和英国等。官方网站:https://shoc...

易探云香港vps主机价格多少钱?香港云服务器主机租用价格

易探云香港vps主机价格多少钱?香港vps主机租用费用大体上是由配置决定的,我们选择香港vps主机租用最大的优势是免备案vps。但是,每家服务商的机房、配置、定价也不同。我们以最基础配置为标准,综合比对各大香港vps主机供应商的价格,即可选到高性能、价格适中的香港vps主机。通常1核CPU、1G内存、2Mbps独享带宽,价格在30元-120元/月。不过,易探云香港vps主机推出四个机房的优惠活动,...

awakefromnib为你推荐
洗牌算法我是小白,eclipse说老式声明,怎么办?帮我看下,不胜感激!! //发牌算法qq号查询怎样查找本地qq号码representspublic class是什么意思tvosios,tvos,watchos和os x的区别tvosTVOS智能电视操作系统如何越狱jdk6java—JDK6,在SUN公司官网下载的链接,flowplayerswfobject.js这能不能播放音频啊(amr)有b吗34B的胸围有多大?smartupload使用SmartUpload实现文件上传时需要对表单设置哪些属性booth算法利用补码booth计算【xy】补,其中x=0.1110,y=-0.1101
重庆网站空间 中国域名交易中心 2019年感恩节 企业主机 pccw themeforest rackspace godaddy优惠码 服务器日志分析 美国php空间 坐公交投2700元 193邮箱 工作站服务器 1美金 512mb 空间租赁 带宽租赁 cdn服务 数据湾 hdsky 更多