当前位置: 编程技术>移动开发
本页文章导读:
▪格式化帖子时间,依据不同的值显示不同的时间 格式化帖子时间,根据不同的值显示不同的时间
public static String getSendedTime(long oldTime) { String sTime = null; long today0HourTime = getTodayTimeMillis(); if (oldTime < today0HourTime) { long lTime = today0HourTime.........
▪ 视图切换的动画片效果 视图切换的动画效果
为了避免视图之间切换的呆板问题,在IPHONE中引入了转换动画效果,分别在UIKit.framework和QuartzCore.framework中,后者的动画类型要比前者丰富一些。
- (IBAction)switchViews:(id).........
▪ 统制不同的文字字体 控制不同的文字字体
TextView对象中有许多与字形相关的方法,使用setTextSize方法来改变字体大小,用setTypeface方法来指定使用字体等等。 如果你想使用内部默认的Typeface,用defaultFromStyle.........
[1]格式化帖子时间,依据不同的值显示不同的时间
来源: 互联网 发布时间: 2014-02-18
格式化帖子时间,根据不同的值显示不同的时间
public static String getSendedTime(long oldTime) {
String sTime = null;
long today0HourTime = getTodayTimeMillis();
if (oldTime < today0HourTime) {
long lTime = today0HourTime - oldTime;
int num = (int) (lTime / oneDay);
if (num >= 0 && num <2) {
sTime = strTime[num];
}else if(num >= 2 && num <= 6){
sTime = strTime[2];
}else{
sTime = getTimeByLong(oldTime, "M月d日");
}
} else {
sTime = getTimeByLong(oldTime, "HH:mm");
}
return sTime;
}
public static String getTimeByLong(long tLong, String format) {
String strDate = "";
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(tLong);
cal.setTimeZone(TimeZone.getTimeZone("GMT+8"));
SimpleDateFormat sdf = new SimpleDateFormat(format);
strDate = sdf.format(cal.getTime());
return strDate;
}
private static long getTodayTimeMillis() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTimeInMillis();
}
// *******************************************************
private final static long oneDay = 24 * 60 * 60 * 1000;
private static String[] strTime = { "昨天", "前天", "三天前" };
public static String getSendedTime(long oldTime) {
String sTime = null;
long today0HourTime = getTodayTimeMillis();
if (oldTime < today0HourTime) {
long lTime = today0HourTime - oldTime;
int num = (int) (lTime / oneDay);
if (num >= 0 && num <2) {
sTime = strTime[num];
}else if(num >= 2 && num <= 6){
sTime = strTime[2];
}else{
sTime = getTimeByLong(oldTime, "M月d日");
}
} else {
sTime = getTimeByLong(oldTime, "HH:mm");
}
return sTime;
}
public static String getTimeByLong(long tLong, String format) {
String strDate = "";
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(tLong);
cal.setTimeZone(TimeZone.getTimeZone("GMT+8"));
SimpleDateFormat sdf = new SimpleDateFormat(format);
strDate = sdf.format(cal.getTime());
return strDate;
}
private static long getTodayTimeMillis() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTimeInMillis();
}
// *******************************************************
private final static long oneDay = 24 * 60 * 60 * 1000;
private static String[] strTime = { "昨天", "前天", "三天前" };
[2] 视图切换的动画片效果
来源: 互联网 发布时间: 2014-02-18
视图切换的动画效果
为了避免视图之间切换的呆板问题,在IPHONE中引入了转换动画效果,分别在UIKit.framework和QuartzCore.framework中,后者的动画类型要比前者丰富一些。
- (IBAction)switchViews:(id)sender{ //准备动画 [UIView beginAnimations:@"animationID" context:nil]; //动画播放持续时间 [UIView setAnimationDuration:0.5f]; //动画速度 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationRepeatAutoreverses:NO]; UIButton *theButton = (UIButton *)sender; //动画方向 switch (theButton.tag) { case 0: [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; break; case 1: [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; break; case 2: [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; break; case 3: [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; break; default: break; } [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; [UIView commitAnimations]; }
下面的动画需要导入QuartzCore.framework库,并在实现文件中导入。
#import <QuartzCore/QuartzCore.h> - (IBAction)switchViews:(id)sender{ //准备动画 CATransition *animation = [CATransition animation]; animation.delegate = self; //动画播放持续时间 animation.duration = 0.5f; //动画速度 animation.timingFunction = UIViewAnimationCurveEaseInOut; animation.fillMode = kCAFillModeForwards; animation.removedOnCompletion = NO; UIButton *theButton = (UIButton *)sender; //动画效果 switch (theButton.tag) { case 0: animation.type = @"cube"; break; case 1: animation.type = @"suckEffect"; break; case 2: animation.type = @"oglFlip"; break; case 3: animation.type = @"rippleEffect"; break; case 4: animation.type = @"pageCurl"; break; case 5: animation.type = @"pageUnCurl"; break; case 6: animation.type = @"cameraIrisHollowOpen "; break; case 7: animation.type = @"cameraIrisHollowClose "; break; default: break; } [self.view.layer addAnimation:animation forKey:@"animation"]; [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; }
下面的动画同样需要导入QuartzCore.framework库,并在实现文件中导入。
#import <QuartzCore/QuartzCore.h> - (IBAction)switchViews:(id)sender{ CATransition *animation = [CATransition animation]; animation.duration = 0.5f; animation.timingFunction = UIViewAnimationCurveEaseInOut; animation.fillMode = kCAFillModeForwards; UIButton *theButton = (UIButton *)sender; switch (theButton.tag) { case 0: /*动画效果 kCATransitionFade kCATransitionMoveIn kCATransitionPush kCATransitionReveal */ animation.type = kCATransitionPush; /*动画方向 kCATransitionFromRight kCATransitionFromLeft kCATransitionFromTop kCATransitionFromBottom */ animation.subtype = kCATransitionFromTop; break; case 1: animation.type = kCATransitionMoveIn; animation.subtype = kCATransitionFromTop; break; case 2: animation.type = kCATransitionReveal; animation.subtype = kCATransitionFromTop; break; case 3: animation.type = kCATransitionFade; animation.subtype = kCATransitionFromTop; break; default: break; } [self.view.layer addAnimation:animation forKey:@"animation"]; }
UIKit.framework中的动画是对UIView的,而QuartzCore.framework是针对视图的属性layer来实现的,后者与视图动画比起来,具备更大的优势,更容易进行转换,倾斜,放大,缩小等等。
[3] 统制不同的文字字体
来源: 互联网 发布时间: 2014-02-18
控制不同的文字字体
TextView对象中有许多与字形相关的方法,使用setTextSize方法来改变字体大小,用setTypeface方法来指定使用字体等等。
如果你想使用内部默认的Typeface,用defaultFromStyle()方法即可。但是,如果你想要通过外部的资源来构造Typeface,步骤如下:
1. 事先在assets目录下创建一个fonts文件夹
2. 放入要使用的字体文件(.ttf)
3. 提供相对路径给createFromAsset()来创建Typeface对象
使用外部Typeface如下:
eg.
使用内部Typeface,如下:
完整代码:
TextView对象中有许多与字形相关的方法,使用setTextSize方法来改变字体大小,用setTypeface方法来指定使用字体等等。
如果你想使用内部默认的Typeface,用defaultFromStyle()方法即可。但是,如果你想要通过外部的资源来构造Typeface,步骤如下:
1. 事先在assets目录下创建一个fonts文件夹
2. 放入要使用的字体文件(.ttf)
3. 提供相对路径给createFromAsset()来创建Typeface对象
使用外部Typeface如下:
eg.
textview.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/HandmadeTypewriter.ttf"));
使用内部Typeface,如下:
website.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
完整代码:
package com.kevin.textview; import android.app.Activity; import android.content.res.Resources; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.TextView; public class TextViewActivity extends Activity { private TextView website, email, phone; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); website = (TextView) findViewById(R.id.tv_website); email = (TextView)findViewById(R.id.tv_email); phone = (TextView) findViewById(R.id.tv_phone); // 设置文本值 website.setText(R.string.website); email.setText(R.string.email); phone.setText(R.string.phone); // 设置字体大小 website.setTextSize(20); // 设置字体 /* * 使用内部默认的Typeface,用defaultFromStyle()方法 * 如果你想要通过外部的资源来构造Typeface,步骤如下: * 1. 事先在assets目录下创建一个fonts文件夹 * 2. 放入要使用的字体文件(.ttf) * 3. 提供相对路径给createFromAsset()来创建Typeface对象 */ website.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); } }
最新技术文章: