当前位置:  编程技术>移动开发
本页文章导读:
    ▪DTCoreText的运用        DTCoreText的使用 GitHub: https://github.com/Cocoanetics/DTCoreText 接口文档说明: https://docs.cocoanetics.com/DTCoreText/   DTCoreText库包含三部分Parsing,Layouting,UI。 其中UI包含了我们常使用的类: DTAttributedLa.........
    ▪ UIView的扩充类        UIView的扩展类 ExtUIView.h   @interface UIView (autoresizing) //带margin的左中右层 - (void) addSubviewLeft:(UIView *)leftView middleView:(UIView *)middleView rightView:(UIView *)rightView lefWidth:(CGFloat)lefWidth rightWidth:(CGFloat)ri.........
    ▪ 组合popwindow与gridview的一例       结合popwindow与gridview的一例 项目中需要实现一个gridview 点击某项弹出一个popupwindow 最蛋疼的是一个突出的尖角指定点击的哪一项   然后还需要判断底部空间是否足够显示弹出的popupwindow  这.........

[1]DTCoreText的运用
    来源: 互联网  发布时间: 2014-02-18
DTCoreText的使用

GitHub:

https://github.com/Cocoanetics/DTCoreText

接口文档说明:

https://docs.cocoanetics.com/DTCoreText/

 

DTCoreText库包含三部分Parsing,Layouting,UI。

其中UI包含了我们常使用的类:

DTAttributedLabel 

用来代替UILabel使用的控件,显示富文本,继承自 DTAttributedTextContentView,可以使用delegate来处理image和hyperlink。

DTAttributedTextCell

作为tableViewCell来使用

DTAttributedTextContentView

用来显示富文本,不应该直接被使用。

DTAttributedTextView

用来代替UITextView,继承自UIScrollView,里面放置了一个DTAttributedTextContentView用来显示内容

DTLazyImageView

DTWebVideoView 

DTLinkButton  每个超链接都转化为一个DTLinkButton来使用

 

 setup:

Linking里的Other Linker Flags

Search Paths里的Header Search Paths 

 


    
[2] UIView的扩充类
    来源: 互联网  发布时间: 2014-02-18
UIView的扩展类

ExtUIView.h

 

@interface UIView (autoresizing)
//带margin的左中右层
- (void) addSubviewLeft:(UIView *)leftView  middleView:(UIView *)middleView rightView:(UIView *)rightView lefWidth:(CGFloat)lefWidth  rightWidth:(CGFloat)rightWidth margin:(CGRect)marginFrame;
//左中右层
- (void) addSubviewLeft:(UIView *)leftView  middleView:(UIView *)middleView rightView:(UIView *)rightView lefWidth:(CGFloat)lefWidth  rightWidth:(CGFloat)rightWidth;
//上中下层
- (void) addSubviewTop:(UIView *)topView  middleView:(UIView *)middleView bottomView:(UIView *)bottomView topHeight:(CGFloat)topHeight  bottomHeight:(CGFloat)bottomHeight;

//左上右下 自适应大小来满足margin
- (void) addSubview:(UIView *)aView  margin:(CGRect)marginFrame;
//自适应margin来满足大小
- (void) addSubview:(UIView *)aView  size:(CGSize)aSize;
//左上右下 自适应大小来满足margin
- (void) setSizeInView:(UIView *)aView margin:(CGRect)marginFrame;
//左上右下 自适应margin来满足大小

- (void) setCenterInView:(UIView *)aView size:(CGSize)aSize;
- (CGPoint) centerPoint;

@end

 

ExtUIView.m

 

#import "ExtUIView.h"

@implementation UIView (autoresizing)

- (void) addSubviewLeft:(UIView *)leftView  middleView:(UIView *)middleView rightView:(UIView *)rightView lefWidth:(CGFloat)lefWidth  rightWidth:(CGFloat)rightWidth margin:(CGRect)marginFrame {
	;
}

- (void) addSubviewLeft:(UIView *)leftView  middleView:(UIView *)middleView rightView:(UIView *)rightView lefWidth:(CGFloat)lefWidth  rightWidth:(CGFloat)rightWidth {
	if(leftView) {
		leftView.frame = CGRectMake(0, 0, lefWidth, self.frame.size.height);
		leftView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin;
		[self addSubview:leftView];
	}
	if(middleView) {
		middleView.frame = CGRectMake(lefWidth, 0, self.frame.size.width - lefWidth - rightWidth, self.frame.size.height);
		middleView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
		[self addSubview:middleView];
	}
	if(rightView) {
		rightView.frame = CGRectMake(self.frame.size.width - rightWidth, 0, rightWidth, self.frame.size.height);
		rightView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin ;
		[self addSubview:rightView];
	}
}

- (void) addSubviewTop:(UIView *)topView  middleView:(UIView *)middleView bottomView:(UIView *)bottomView topHeight:(CGFloat)topHeight  bottomHeight:(CGFloat)bottomHeight {
	if(topView) {
		topView.frame = CGRectMake(0, 0, self.frame.size.width, topHeight);
		topView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
		[self addSubview:topView];
	}
	if(middleView) {
		middleView.frame = CGRectMake(0, topHeight, self.bounds.size.width, self.frame.size.height - topHeight - bottomHeight);
		middleView.autoresizingMask =UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth ;
		[self addSubview:middleView];
	}
	if(bottomView) {
		bottomView.frame = CGRectMake(0, self.frame.size.height - bottomHeight, self.frame.size.width, bottomHeight);
		bottomView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin ;
		[self addSubview:bottomView];
	}
}

//左上右下
- (void) addSubview:(UIView *)aView  margin:(CGRect)marginFrame {
	if (!aView) return;
	aView.frame = CGRectMake(marginFrame.origin.x, marginFrame.origin.y, self.frame.size.width - marginFrame.origin.x - marginFrame.size.width, self.frame.size.height - marginFrame.origin.y - marginFrame.size.height);
	aView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
	[self addSubview:aView];
}

- (void) addSubview:(UIView *)aView  size:(CGSize)aSize {
	if (!aView) return;
	aView.center = [self centerPoint];
	aView.bounds = CGRectMake(0, 0, aSize.width, aSize.height);
	aView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
	[self addSubview:aView];
}

//左上右下
- (void) setSizeInView:(UIView *)aView margin:(CGRect)marginFrame {
	if (!aView) return;
	self.frame = CGRectMake(marginFrame.origin.x, marginFrame.origin.y, aView.frame.size.width - marginFrame.origin.x - marginFrame.size.width, aView.frame.size.height - marginFrame.origin.y - marginFrame.size.height);
	self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
}

- (void) setCenterInView:(UIView *)aView size:(CGSize)aSize {
	if (!aView) return;
	self.center = [aView centerPoint];
	self.bounds = CGRectMake(0, 0, aSize.width, aSize.height);
	self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin |UIViewAutoresizingFlexibleBottomMargin;
}

- (CGPoint) centerPoint {
	return CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
}

@end

 

示例:

 

UIView *v1 = [[[UIView alloc] init] autorelease];
UIView *v2 = [[[UIView alloc] init] autorelease];
UIView *v3 = [[[UIView alloc] init] autorelease];

UIView *v4 = [[[UIView alloc] init] autorelease];
UIView *v5 = [[[UIView alloc] init] autorelease];
UIView *v6 = [[[UIView alloc] init] autorelease];

UIView *v7 = [[[UIView alloc] init] autorelease];
UIView *v8 = [[[UIView alloc] init] autorelease];
UIView *v9 = [[[UIView alloc] init] autorelease];

UIView *v10 = [[[UIView alloc] init] autorelease];
UIView *v11 = [[[UIView alloc] init] autorelease];
UIView *v12 = [[[UIView alloc] init] autorelease];

v1.backgroundColor=[UIColor cyanColor];
v2.backgroundColor=[UIColor grayColor];
v3.backgroundColor=[UIColor greenColor];

v4.backgroundColor=[UIColor greenColor];
v5.backgroundColor=[UIColor blackColor];
v6.backgroundColor=[UIColor cyanColor];

v7.backgroundColor=[UIColor darkGrayColor];
v8.backgroundColor=[UIColor lightGrayColor];
v9.backgroundColor=[UIColor whiteColor];

v10.backgroundColor=[UIColor blackColor];
v11.backgroundColor=[UIColor orangeColor];
v12.backgroundColor=[UIColor purpleColor];

[self.view addSubviewLeft:v1 middleView:v2 rightView:v3 lefWidth:100.0 rightWidth:100.0];
[v1 addSubviewTop:v7 middleView:v8 bottomView:v9 topHeight:100 bottomHeight:50];

[v8 addSubview:v4 size:CGSizeMake(15, 15)];
[v2 addSubview:v5 size:CGSizeMake(55, 55)];
[v3 addSubview:v6 size:CGSizeMake(15, 15)];

[v9 addSubview:v10 margin:CGRectMake(10, 10, 10, 10)];
[v11 setCenterInView:v2 size:CGSizeMake(50, 50)];
[v12 setSizeInView:v2 margin:CGRectMake(50, 10, 50, 100)];

[v2 addSubview:v11];
[v2 addSubview:v12];

 

示例图:



    
[3] 组合popwindow与gridview的一例
    来源: 互联网  发布时间: 2014-02-18
结合popwindow与gridview的一例

项目中需要实现一个gridview 点击某项弹出一个popupwindow 最蛋疼的是一个突出的尖角指定点击的哪一项


 

然后还需要判断底部空间是否足够显示弹出的popupwindow 

这个功能点 我遇到了两个问题

 

第一个就是尖角的定位了 在一个地方困住了好久 

点击某一个item 这时候getTop的值实际是到parentView的距离 这里我漏掉了顶部状态栏的大小 在不同手机上测试 效果始终不理想。

首先是获取状态类高度

Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
return frame.top;

 这个方法在oncreate中只会返回0 因为这时候实际上还没有开始页面的绘画 所以我放在了点击监听器中。

如此在监听器中弹出popupwindow就可以比较精确的定位了

 

 第二个算是小问题

  怎么在popupwindow弹出的情况下 点击外部区域自动关闭 以为很复杂 结果就是3行代码

popWin = new PopupWindow(popview, dm.widthPixels, 106);//没有设置为focusable
popWin.setBackgroundDrawable(new BitmapDrawable());//不明
popWin.setOutsideTouchable(true);

 

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
nosql iis7站长之家
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3