当前位置: 编程技术>移动开发
本页文章导读:
▪实现不选择选项则不可以关闭的对话框之步骤三 实现不选择选项则不可以关闭的对话框之方法三
本方法基于Dialog,使用自定义布局,更能满足发杂的需求。
布局文件:dialog_must_enter.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:.........
▪ 加载plist粒子奇效文件方法 加载plist粒子特效文件方法
cocos2d-x 3.0alpha0
ParticleSystem* ps = ParticleSystemQuad::create("particle/ball.plist");
ps->setPosition(center);
addChild(ps, 1, 0x02);
......
▪ UITextField使用总结(一) UITextField使用小结(一)
_textField.frame = CGRectMake(0, 0, 200, 50);
_textField.delegate = self;
_textField.text = str;
[_textField becomeFirstResponder];
/*
设置背景色、背景图片。设置了.........
[1]实现不选择选项则不可以关闭的对话框之步骤三
来源: 互联网 发布时间: 2014-02-18
实现不选择选项则不可以关闭的对话框之方法三
本方法基于Dialog,使用自定义布局,更能满足发杂的需求。
布局文件:dialog_must_enter.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_horizontal_margin" >
<TextView
android:id="@+id/txtUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/edtUsername"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="姓名: " />
<EditText
android:id="@+id/edtUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/txtUsername"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/txtHorizontalCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btnOK"
android:layout_below="@+id/edtUsername"
android:layout_centerHorizontal="true"
android:text="" />
<Button
android:id="@+id/btnOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edtUsername"
android:layout_toLeftOf="@+id/txtHorizontalCenter"
android:text="确定" />
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/txtHorizontalCenter"
android:layout_toRightOf="@+id/txtHorizontalCenter"
android:text="取消" />
</RelativeLayout>
Java代码:
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button btnOpenDialog;
private Activity activity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
activity = this;
btnOpenDialog = (Button) findViewById(R.id.btnOpenDialog);
btnOpenDialog.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(activity);
dialog.setContentView(R.layout.dialog_must_enter);
dialog.setTitle("必填项Demo");
final EditText edtUserName = (EditText) dialog.findViewById(R.id.edtUsername);
Button btnOKOfDialog = (Button) dialog.findViewById(R.id.btnOK);
btnOKOfDialog.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!TextUtils.isEmpty(edtUserName.getText().toString().trim())) {
dialog.dismiss();
} else {
Toast.makeText(activity, "姓名不能为空!", Toast.LENGTH_LONG).show();
}
}
});
Button btnCancelOfDialog = (Button) dialog.findViewById(R.id.btnCancel);
btnCancelOfDialog.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
}
}
[2] 加载plist粒子奇效文件方法
来源: 互联网 发布时间: 2014-02-18
加载plist粒子特效文件方法
cocos2d-x 3.0alpha0
cocos2d-x 3.0alpha0
ParticleSystem* ps = ParticleSystemQuad::create("particle/ball.plist");
ps->setPosition(center);
addChild(ps, 1, 0x02);
[3] UITextField使用总结(一)
来源: 互联网 发布时间: 2014-02-18
UITextField使用小结(一)
_textField.frame = CGRectMake(0, 0, 200, 50);
_textField.delegate = self;
_textField.text = str;
[_textField becomeFirstResponder];
/*
设置背景色、背景图片。设置了背景图片后,背景色设置无效
如果background为nil,disabledBackground无效
*/
_textField.background = [UIImage imageNamed:@"返回-按下"];
_textField.disabledBackground = [UIImage imageNamed:@"返回-未激活"];
// _textField.enabled = NO;
_textField.backgroundColor = [UIColor blueColor];
_textField.placeholder = @"输入文本…";
/*
设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动
*/
_textField.adjustsFontSizeToFitWidth = YES;
//设置自动缩小显示的最小字体大小,adjustsFontSizeToFitWidth为YES才会起作用
_textField.minimumFontSize = 20;
_textField.font = [UIFont systemFontOfSize:30.0f];
/*
内容对齐方式
内容的垂直对齐方式 UITextField继承自UIControl,此类中有一个属性contentVerticalAlignment
*/
_textField.textAlignment = UITextAlignmentLeft;
_textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
/*
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
*/
_textField.borderStyle = UITextBorderStyleBezel;
/*
每输入一个字符就变成点 用语密码输入
*/
_textField.secureTextEntry = NO;
/*
//输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
typedef enum {
UITextFieldViewModeNever, 重不出现
UITextFieldViewModeWhileEditing, 编辑时出现
UITextFieldViewModeUnlessEditing, 除了编辑外都出现
UITextFieldViewModeAlways 一直出现
} UITextFieldViewMode;
*/
_textField.clearButtonMode = UITextFieldViewModeWhileEditing;
/*
开始编辑,清空数据
*/
_textField.clearsOnBeginEditing = NO;
/*
//是否纠错
typedef enum {
UITextAutocorrectionTypeDefault, 默认
UITextAutocorrectionTypeNo, 不自动纠错
UITextAutocorrectionTypeYes, 自动纠错
} UITextAutocorrectionType;
*/
_textField.autocorrectionType = UITextAutocorrectionTypeYes;
/*
//首字母是否大写
typedef enum {
UITextAutocapitalizationTypeNone, 不自动大写
UITextAutocapitalizationTypeWords, 单词首字母大写
UITextAutocapitalizationTypeSentences, 句子的首字母大写
UITextAutocapitalizationTypeAllCharacters, 所有字母都大写
} UITextAutocapitalizationType;
*/
_textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
/*
键盘
typedef enum {
UIKeyboardTypeDefault, 默认键盘,支持所有字符
UIKeyboardTypeASCIICapable, 支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, 标准电话键盘,支持+*#字符
UIKeyboardTypeURL, URL键盘,支持.com按钮 只支持URL字符
UIKeyboardTypeNumberPad, 数字键盘
UIKeyboardTypePhonePad, 电话键盘
UIKeyboardTypeNamePhonePad, 电话键盘,也支持输入人名
UIKeyboardTypeEmailAddress, 用于输入电子 邮件地址的键盘
UIKeyboardTypeDecimalPad, 数字键盘 有数字和小数点
UIKeyboardTypeTwitter, 优化的键盘,方便输入@、#字符
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
} UIKeyboardType;
*/
_textField.keyboardType = UIKeyboardTypeDefault;
/*
//return键变成什么键
typedef enum {
UIReturnKeyDefault, 默认 灰色按钮,标有Return
UIReturnKeyGo, 标有Go的蓝色按钮
UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索
UIReturnKeyJoin,标有Join的蓝色按钮
UIReturnKeyNext,标有Next的蓝色按钮
UIReturnKeyRoute,标有Route的蓝色按钮
UIReturnKeySearch,标有Search的蓝色按钮
UIReturnKeySend,标有Send的蓝色按钮
UIReturnKeyYahoo,标有Yahoo的蓝色按钮
UIReturnKeyYahoo,标有Yahoo的蓝色按钮
UIReturnKeyEmergencyCall, 紧急呼叫按钮
} UIReturnKeyType;
*/
_textField.returnKeyType = UIReturnKeyDone;
/*
//键盘外观
typedef enum {
UIKeyboardAppearanceDefault, 默认外观,浅灰色
UIKeyboardAppearanceDark, 深灰 石墨色
UIKeyboardAppearanceLight 浅灰色
} UIReturnKeyType;
*/
_textField.keyboardAppearance=UIKeyboardAppearanceDefault;
/*
设置左右的两个view
*/
// UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_right"]];
// imgView.frame = CGRectMake(0, 0, 20, 20);
// _textField.rightView = imgView;
// _textField.rightViewMode = UITextFieldViewModeAlways; // 同上
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_left"]];
imgView.frame = CGRectMake(0, 0, 20, 20);
_textField.leftView = imgView;
_textField.leftViewMode = UITextFieldViewModeAlways; // 同上
/*
重写绘制行为
除了UITextField对象的风格选项,你还可以定制化UITextField对象,为他添加许多不同的重写方法,来改变文本字段的显示行为。这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围。以下方法都可以重写。
– textRectForBounds: //重写来重置文字区域
– drawTextInRect: //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
– placeholderRectForBounds: //重写来重置占位符区域
– drawPlaceholderInRect: //重写改变绘制占位符属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
– borderRectForBounds: //重写来重置边缘区域
– editingRectForBounds: //重写来重置编辑区域
– clearButtonRectForBounds: //重写来重置clearButton位置,改变size可能导致button的图片失真
– leftViewRectForBounds:
– rightViewRectForBounds:
*/
UITextField使用小结(二)
http://quding0308.iteye.com/admin/blogs/1681180
最新技术文章: