当前位置: 编程技术>移动开发
本页文章导读:
▪兑现类似微博的BottomBar 实现类似微博的BottomBar
主要布局:
package com.test.activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.Ra.........
▪ 水准滑动的ListView 水平滑动的ListView
package com.m4399.gamecenter.widget;
import com.m4399.gamecenter.util.LogTag;
import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleO.........
▪ 取得通讯录中联系人的所有属性ABAddressBookRef 获得通讯录中联系人的所有属性ABAddressBookRef
获得通讯录中联系人的所有属性 ,看代码: ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addres.........
[1]兑现类似微博的BottomBar
来源: 互联网 发布时间: 2014-02-18
实现类似微博的BottomBar
主要布局:
package com.test.activity; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.view.Window; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.TabHost; import com.test.testbottombar.R; /** * MainTabAcitivity * @author LinHang_He * */ public class MainTabActivity extends TabActivity implements OnCheckedChangeListener{ private RadioGroup mainTab; private TabHost mTabHost; //内容Intent private Intent mHomeIntent; private Intent mNewsIntent; private Intent mInfoIntent; private Intent mSearchIntent; private Intent mMoreIntent; private final static String TAB_TAG_HOME="tab_tag_home"; private final static String TAB_TAG_NEWS="tab_tag_news"; private final static String TAB_TAG_INFO="tab_tag_info"; private final static String TAB_TAG_SEARCH="tab_tag_search"; private final static String TAB_TAG_MORE="tab_tag_more"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); mainTab=(RadioGroup)findViewById(R.id.main_tab); mainTab.setOnCheckedChangeListener(this); prepareIntent(); setupIntent(); } /** * 准备tab的内容Intent */ private void prepareIntent() { //mHomeIntent=new Intent(this, HomeActivity.class); mHomeIntent=new Intent(this, FriendsDynamicActivity.class); mNewsIntent=new Intent(this, InfoActivity.class); mInfoIntent=new Intent(this, FriendsOrGroupActivity.class); mSearchIntent=new Intent(this,SquareActivity.class); mMoreIntent=new Intent(this, MoreActivity.class); } /** * */ private void setupIntent() { this.mTabHost=getTabHost(); TabHost localTabHost=this.mTabHost; localTabHost.addTab(buildTabSpec(TAB_TAG_HOME, R.string.main_home, R.drawable.icon_1_n, mHomeIntent)); localTabHost.addTab(buildTabSpec(TAB_TAG_NEWS, R.string.main_news, R.drawable.icon_2_n, mNewsIntent)); localTabHost.addTab(buildTabSpec(TAB_TAG_INFO, R.string.main_my_info, R.drawable.icon_3_n, mInfoIntent)); localTabHost.addTab(buildTabSpec(TAB_TAG_SEARCH, R.string.menu_search, R.drawable.icon_4_n, mSearchIntent)); localTabHost.addTab(buildTabSpec(TAB_TAG_MORE, R.string.more, R.drawable.icon_5_n, mMoreIntent)); } private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,final Intent content) { return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel), getResources().getDrawable(resIcon)).setContent(content); } public void onCheckedChanged(RadioGroup group, int checkedId) { switch(checkedId){ case R.id.radio_button0: this.mTabHost.setCurrentTabByTag(TAB_TAG_HOME); break; case R.id.radio_button1: this.mTabHost.setCurrentTabByTag(TAB_TAG_NEWS); break; case R.id.radio_button2: this.mTabHost.setCurrentTabByTag(TAB_TAG_INFO); break; case R.id.radio_button3: this.mTabHost.setCurrentTabByTag(TAB_TAG_SEARCH); break; case R.id.radio_button4: this.mTabHost.setCurrentTabByTag(TAB_TAG_MORE); break; } } }
创建需要的5个Activity
布局文件main.xml
<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0.0dip" android:layout_weight="1.0"/> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" android:visibility="gone"/> <RadioGroup android:id="@+id/main_tab" android:background="@drawable/maintab_toolbar_bg" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_gravity="bottom"> <RadioButton android:layout_marginTop="2.0dip" android:text="@string/main_home" android:drawableTop="@drawable/icon_1_n" android:id="@+id/radio_button0" /> <RadioButton android:layout_marginTop="2.0dip" android:text="@string/main_news" android:drawableTop="@drawable/icon_2_n" android:id="@+id/radio_button1" /> <RadioButton android:layout_marginTop="2.0dip" android:text="@string/main_my_info" android:drawableTop="@drawable/icon_3_n" android:id="@+id/radio_button2" /> <RadioButton android:layout_marginTop="2.0dip" android:text="@string/menu_search" android:drawableTop="@drawable/icon_4_n" android:id="@+id/radio_button3" /> <RadioButton android:layout_marginTop="2.0dip" android:text="@string/more" android:drawableTop="@drawable/icon_5_n" android:id="@+id/radio_button4" /> </RadioGroup> </LinearLayout> </TabHost>
创建drawable文件夹,添加home_btn_bg.xml
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/home_btn_bg_d"/> <item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/home_btn_bg_d" /> <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/home_btn_bg_d" /> <item android:drawable="@drawable/transparent" /> </selector>
在values文件夹下添加dimens.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="bottom_tab_padding_drawable">2.0dip</dimen> <dimen name="bottom_tab_padding_up">5.0dip</dimen> <dimen name="bottom_tab_font_size">10.0dip</dimen> </resources>
在values文件夹下添加drawables.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <item type="drawable" name="transparent">#00000000</item> </resources>
strings.xml
<resources> <string name="app_name">TestBottomBar</string> <string name="main_home">首页</string> <string name="main_news">新闻</string> <string name="main_my_info">信息</string> <string name="menu_search">搜索</string> <string name="more">更多</string> </resources>
styles.xml
<resources> <style name="AppTheme" parent="android:Theme.Light" /> <style name="main_tab_bottom"> <item name="android:textSize">@dimen/bottom_tab_font_size</item> <item name="android:textColor">#ffffffff</item> <item name="android:ellipsize">marquee</item> <item name="android:gravity">center_horizontal</item> <item name="android:background">@drawable/home_btn_bg</item> <item name="android:paddingTop">@dimen/bottom_tab_padding_up</item> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:button">@null</item> <item name="android:singleLine">true</item> <item name="android:drawablePadding">@dimen/bottom_tab_padding_drawable</item> <item name="android:layout_weight">1.0</item> </style> </resources>
[2] 水准滑动的ListView
来源: 互联网 发布时间: 2014-02-18
水平滑动的ListView
package com.m4399.gamecenter.widget; import com.m4399.gamecenter.util.LogTag; import android.content.Context; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; import android.view.View; import android.widget.ListView; /** * 解决横向滑动控件在ListView中的减点问题的ListView * * @author LRChao * @date 2013-3-6 * */ public class HorizontalScrollListView extends ListView { private final String TAG = "HorizontalScrollListView"; private GestureDetector mGestureDetector; View.OnTouchListener mGestureListener; public HorizontalScrollListView(Context context) { super(context); } public HorizontalScrollListView(Context context, AttributeSet attrs) { super(context, attrs); mGestureDetector = new GestureDetector(new YScrollDetector()); setFadingEdgeLength(0); } public HorizontalScrollListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { // getParent().requestDisallowInterceptTouchEvent(true); // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // LogTag.showTAG_e("onInterceptTouchEvent", "ACTION_DOWN"); // break; // case MotionEvent.ACTION_UP: // LogTag.showTAG_e("onInterceptTouchEvent", "ACTION_UP"); // break; // case MotionEvent.ACTION_MOVE: // LogTag.showTAG_e("onInterceptTouchEvent", "ACTION_MOVE"); // break; // // default: // break; // } LogTag.showTAG_e("onInterceptTouchEvent", super.onInterceptTouchEvent(ev) || mGestureDetector.onTouchEvent(ev)); return super.onInterceptTouchEvent(ev) || mGestureDetector.onTouchEvent(ev); } class YScrollDetector extends SimpleOnGestureListener { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if(distanceY !=0 && distanceX != 0){ if (Math.abs(distanceY) >= Math.abs(distanceX)) { return true; } return false; } return false; } } // @Override // public boolean onTouchEvent(MotionEvent ev) { // switch (ev.getAction()) { // case MotionEvent.ACTION_DOWN: // LogTag.showTAG_e("onTouchEvent", "ACTION_DOWN"); // break; // case MotionEvent.ACTION_UP: // LogTag.showTAG_e("onTouchEvent", "ACTION_UP"); // break; // case MotionEvent.ACTION_MOVE: // LogTag.showTAG_e("onTouchEvent", "ACTION_MOVE"); // break; // // // default: // break; // } // LogTag.showTAG_e("onTouchEvent", super.onTouchEvent(ev)); // LogTag.showTAG_e("onTouchEvent", super.onTouchEvent(ev)|| mGestureDetector.onTouchEvent(ev)); // return super.onTouchEvent(ev); // } }
[3] 取得通讯录中联系人的所有属性ABAddressBookRef
来源: 互联网 发布时间: 2014-02-18
获得通讯录中联系人的所有属性ABAddressBookRef
获得通讯录中联系人的所有属性 ,看代码:
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook);
for(int i = 0; i < CFArrayGetCount(results); i++)
{
ABRecordRef person = CFArrayGetValueAtIndex(results, i);
//读取firstname
NSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
if(personName != nil)
textView.text = [textView.text stringByAppendingFormat:@"\n姓名:%@\n",personName];
//读取lastname
NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
if(lastname != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastname];
//读取middlename
NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);
if(middlename != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlename];
//读取prefix前缀
NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);
if(prefix != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",prefix];
//读取suffix后缀
NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);
if(suffix != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",suffix];
//读取nickname呢称
NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);
if(nickname != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",nickname];
//读取firstname拼音音标
NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);
if(firstnamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",firstnamePhonetic];
//读取lastname拼音音标
NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);
if(lastnamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastnamePhonetic];
//读取middlename拼音音标
NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);
if(middlenamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlenamePhonetic];
//读取organization公司
NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);
if(organization != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",organization];
//读取jobtitle工作
NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);
if(jobtitle != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",jobtitle];
//读取department部门
NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);
if(department != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",department];
//读取birthday生日
NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);
if(birthday != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",birthday];
//读取note备忘录
NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);
if(note != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",note];
//第一次添加该条记录的时间
NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty);
NSLog(@"第一次添加该条记录的时间%@\n",firstknow);
//最后一次修改該条记录的时间
NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty);
NSLog(@"最后一次修改該条记录的时间%@\n",lastknow);
//获取email多值
ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
int emailcount = ABMultiValueGetCount(email);
for (int x = 0; x < emailcount; x++)
{
//获取email Label
NSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x));
//获取email值
NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",emailLabel,emailContent];
}
//读取地址多值
ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);
int count = ABMultiValueGetCount(address);
for(int j = 0; j < count; j++)
{
//获取地址Label
NSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j);
textView.text = [textView.text stringByAppendingFormat:@"%@\n",addressLabel];
//获取該label下的地址6属性
NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j);
NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];
if(country != nil)
textView.text = [textView.text stringByAppendingFormat:@"国家:%@\n",country];
NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];
if(city != nil)
textView.text = [textView.text stringByAppendingFormat:@"城市:%@\n",city];
NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];
if(state != nil)
textView.text = [textView.text stringByAppendingFormat:@"省:%@\n",state];
NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];
if(street != nil)
textView.text = [textView.text stringByAppendingFormat:@"街道:%@\n",street];
NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];
if(zip != nil)
textView.text = [textView.text stringByAppendingFormat:@"邮编:%@\n",zip];
NSString* coutntrycode = [personaddress valueForKey:(NSString *)kABPersonAddressCountryCodeKey];
if(coutntrycode != nil)
textView.text = [textView.text stringByAppendingFormat:@"国家编号:%@\n",coutntrycode];
}
//获取dates多值
ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty);
int datescount = ABMultiValueGetCount(dates);
for (int y = 0; y < datescount; y++)
{
//获取dates Label
NSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));
//获取dates值
NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",datesLabel,datesContent];
}
//获取kind值
CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);
if (recordType == kABPersonKindOrganization) {
// it's a company
NSLog(@"it's a company\n");
} else {
// it's a person, resource, or room
NSLog(@"it's a person, resource, or room\n");
}
//获取IM多值
ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);
for (int l = 1; l < ABMultiValueGetCount(instantMessage); l++)
{
//获取IM Label
NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);
textView.text = [textView.text stringByAppendingFormat:@"%@\n",instantMessageLabel];
//获取該label下的2属性
NSDictionary* instantMessageContent =(NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l);
NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey];
if(username != nil)
textView.text = [textView.text stringByAppendingFormat:@"username:%@\n",username];
NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey];
if(service != nil)
textView.text = [textView.text stringByAppendingFormat:@"service:%@\n",service];
}
//读取电话多值
ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
for (int k = 0; k<ABMultiValueGetCount(phone); k++)
{
//获取电话Label
NSString * personPhoneLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k));
//获取該Label下的电话值
NSString * personPhone = (NSString*)ABMultiValueCopyValueAtIndex(phone, k);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",personPhoneLabel,personPhone];
}
//获取URL多值
ABMultiValueRef url = ABRecordCopyValue(person, kABPersonURLProperty);
for (int m = 0; m < ABMultiValueGetCount(url); m++)
{
//获取电话Label
NSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));
//获取該Label下的电话值
NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",urlLabel,urlContent];
}
//读取照片
NSData *image = (NSData*)ABPersonCopyImageData(person);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(200, 0, 50, 50)];
[myImage setImage:[UIImage imageWithData:image]];
myImage.opaque = YES;
[textView addSubview:myImage];
}
CFRelease(results);
CFRelease(addressBook);
原帖地址:http://www.cocoachina.com/bbs/read.php?tid=62527&fpage=2
获得通讯录中联系人的所有属性 ,看代码:
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook);
for(int i = 0; i < CFArrayGetCount(results); i++)
{
ABRecordRef person = CFArrayGetValueAtIndex(results, i);
//读取firstname
NSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
if(personName != nil)
textView.text = [textView.text stringByAppendingFormat:@"\n姓名:%@\n",personName];
//读取lastname
NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
if(lastname != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastname];
//读取middlename
NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);
if(middlename != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlename];
//读取prefix前缀
NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);
if(prefix != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",prefix];
//读取suffix后缀
NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);
if(suffix != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",suffix];
//读取nickname呢称
NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);
if(nickname != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",nickname];
//读取firstname拼音音标
NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);
if(firstnamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",firstnamePhonetic];
//读取lastname拼音音标
NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);
if(lastnamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastnamePhonetic];
//读取middlename拼音音标
NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);
if(middlenamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlenamePhonetic];
//读取organization公司
NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);
if(organization != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",organization];
//读取jobtitle工作
NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);
if(jobtitle != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",jobtitle];
//读取department部门
NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);
if(department != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",department];
//读取birthday生日
NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);
if(birthday != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",birthday];
//读取note备忘录
NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);
if(note != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",note];
//第一次添加该条记录的时间
NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty);
NSLog(@"第一次添加该条记录的时间%@\n",firstknow);
//最后一次修改該条记录的时间
NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty);
NSLog(@"最后一次修改該条记录的时间%@\n",lastknow);
//获取email多值
ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
int emailcount = ABMultiValueGetCount(email);
for (int x = 0; x < emailcount; x++)
{
//获取email Label
NSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x));
//获取email值
NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",emailLabel,emailContent];
}
//读取地址多值
ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);
int count = ABMultiValueGetCount(address);
for(int j = 0; j < count; j++)
{
//获取地址Label
NSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j);
textView.text = [textView.text stringByAppendingFormat:@"%@\n",addressLabel];
//获取該label下的地址6属性
NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j);
NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];
if(country != nil)
textView.text = [textView.text stringByAppendingFormat:@"国家:%@\n",country];
NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];
if(city != nil)
textView.text = [textView.text stringByAppendingFormat:@"城市:%@\n",city];
NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];
if(state != nil)
textView.text = [textView.text stringByAppendingFormat:@"省:%@\n",state];
NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];
if(street != nil)
textView.text = [textView.text stringByAppendingFormat:@"街道:%@\n",street];
NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];
if(zip != nil)
textView.text = [textView.text stringByAppendingFormat:@"邮编:%@\n",zip];
NSString* coutntrycode = [personaddress valueForKey:(NSString *)kABPersonAddressCountryCodeKey];
if(coutntrycode != nil)
textView.text = [textView.text stringByAppendingFormat:@"国家编号:%@\n",coutntrycode];
}
//获取dates多值
ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty);
int datescount = ABMultiValueGetCount(dates);
for (int y = 0; y < datescount; y++)
{
//获取dates Label
NSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));
//获取dates值
NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",datesLabel,datesContent];
}
//获取kind值
CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);
if (recordType == kABPersonKindOrganization) {
// it's a company
NSLog(@"it's a company\n");
} else {
// it's a person, resource, or room
NSLog(@"it's a person, resource, or room\n");
}
//获取IM多值
ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);
for (int l = 1; l < ABMultiValueGetCount(instantMessage); l++)
{
//获取IM Label
NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);
textView.text = [textView.text stringByAppendingFormat:@"%@\n",instantMessageLabel];
//获取該label下的2属性
NSDictionary* instantMessageContent =(NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l);
NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey];
if(username != nil)
textView.text = [textView.text stringByAppendingFormat:@"username:%@\n",username];
NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey];
if(service != nil)
textView.text = [textView.text stringByAppendingFormat:@"service:%@\n",service];
}
//读取电话多值
ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
for (int k = 0; k<ABMultiValueGetCount(phone); k++)
{
//获取电话Label
NSString * personPhoneLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k));
//获取該Label下的电话值
NSString * personPhone = (NSString*)ABMultiValueCopyValueAtIndex(phone, k);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",personPhoneLabel,personPhone];
}
//获取URL多值
ABMultiValueRef url = ABRecordCopyValue(person, kABPersonURLProperty);
for (int m = 0; m < ABMultiValueGetCount(url); m++)
{
//获取电话Label
NSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));
//获取該Label下的电话值
NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",urlLabel,urlContent];
}
//读取照片
NSData *image = (NSData*)ABPersonCopyImageData(person);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(200, 0, 50, 50)];
[myImage setImage:[UIImage imageWithData:image]];
myImage.opaque = YES;
[textView addSubview:myImage];
}
CFRelease(results);
CFRelease(addressBook);
原帖地址:http://www.cocoachina.com/bbs/read.php?tid=62527&fpage=2
最新技术文章: