此labelview是用來將label顯示在固定的view上的,需要計算label的高度與寬度.
原始碼:nsstring+stringheight.h 與
nsstring+stringheight.m
//
// nsstring+stringheight.h
// usa
//// created by youxianming on 14/12/10.
//#import @inte***ce nsstring (stringheight)
/** * 計算文字的高度
* * @param font 字型
* @param width 固定的寬度
* * @return 高度
*/- (cgfloat)heightwithlabelfont:(uifont *)font withlabelwidth:(cgfloat)width;
/** * 計算文字的寬度
* * @param font 字型
* * @return 寬度
*/- (cgfloat)widthwithlabelfont:(uifont *)font;
@end
//
// nsstring+stringheight.m
// usa
//// created by youxianming on 14/12/10.
//#import "nsstring+stringheight.h"
@implementation nsstring (stringheight)
- (cgfloat)heightwithlabelfont:(uifont *)font withlabelwidth:(cgfloat)width else ;
if (font) ;
}// 尺寸
cgsize retsize = [self boundingrectwithsize:cgsizemake(width, maxfloat)
options:
nsstringdrawingtruncateslastvisibleline |
nsstringdrawinguseslinefragmentorigin |
nsstringdrawingusesfontleading
attributes:attribute
context:nil].size;
height = retsize.height;
}return height;
}- (cgfloat)widthwithlabelfont:(uifont *)font else ;
if (font) ;
}// 尺寸
cgsize retsize = [self boundingrectwithsize:cgsizemake(maxfloat, 0)
options:
nsstringdrawingtruncateslastvisibleline |
nsstringdrawinguseslinefragmentorigin |
nsstringdrawingusesfontleading
attributes:attribute
context:nil].size;
retheight = retsize.width;
}return retheight;
}@end
labelview.h 與
labelview.m
//
// labelview.h
// yxmweather
//// created by xianmingyou on 15/2/16.
//#import #import "nsstring+stringheight.h"
@inte***ce labelview : uiview
/** * 文字
*/@property (nonatomic, strong) nsstring *text;
/** * 文字顏色
*/@property (nonatomic, strong) uicolor *textcolor;
/** * 文字字型
*/@property (nonatomic, strong) uifont *font;
/** * 背景色
*/@property (nonatomic, strong) uicolor *color;
/** * 距離頂部的距離
*/@property (nonatomic) cgfloat gapfromtop;
/** * 距離底部的距離
*/@property (nonatomic) cgfloat gapfrombottom;
/** * 距離左側的距離
*/@property (nonatomic) cgfloat gapfromleft;
/** * 距離右側的距離
*/@property (nonatomic) cgfloat gapfromright;
/** * 建立出view
*/- (void)buildview;
/** * 建立出缺省配置的label
* * @param text 字串
* @param origin 起始位置
* * @return 例項物件
*/+ (instancetype)createwithtext:(nsstring *)text atorigin:(cgpoint)origin;
@end
//
// labelview.m
// yxmweather
//// created by xianmingyou on 15/2/16.
//#import "labelview.h"
@inte***ce labelview ()
@property (nonatomic) cgfloat labelwidth;
@property (nonatomic) cgfloat labelheight;
@property (nonatomic, strong) uilabel *label;
@end
@implementation labelview
- (void)buildview
}@synthesize label = _label;
- (uilabel *)label
return _label;
}+ (instancetype)createwithtext:(nsstring *)text atorigin:(cgpoint)origin
@end
使用時候的原始碼:
90)];
addsubview:labelview];
控制項 LabelView
此labelview是用來將label顯示在固定的view上的,需要計算label的高度與寬度.原始碼 nsstring stringheight.h 與 nsstring stringheight.m nsstring stringheight.h usa created by youxianmi...
C 控制項 MenuStrip控制項(選單控制項)
一 概述 選單通過存放按照一般主題分組的命令將功能公開給使用者。menustrip 控制項是此版本的 visual studio 和 net framework 中的新功能。使用該控制項,可以輕鬆建立 microsoft office 中那樣的選單。menustrip 控制項支援多文件介面 mdi ...
隱藏控制項 HiddenField控制項
hiddenfield 控制項hiddenfield 控制項顧名思義就是隱藏輸入框的伺服器控制項 它能讓你儲存那些不需要顯示在頁面上的且對安全性要求不高的資料。也許這個時候應該有這麼乙個疑問,為什麼有了 viewstate session 和cookie 等狀態儲存機制,還需要用起 hiddenfi...