IOS學習之UiTableView仿個人中心頁面,據說學會這個控制元件就能裝逼了(二)
蘋果電腦真心不習慣啊,一邊開發使windows一邊是Mac 都不知道按鍵盤哪個鍵了。這UiTableView根android ListView一樣重要,等學會這個以後我就出去裝逼,但願裝逼不要被大神鄙視,哎,沒辦法,半路出家,誰讓我大學學的機械專業,還這麼笨的!如果人生能出來,我要當富二代!好了,不多說了,看賤:不對,看圖:
臥槽,咋這麼大,不管了,男人不都喜歡大嗎?
看程式碼: .h檔案裡面沒東西的我就不貼了:
這是主要程式碼:
得實現兩個協議,根android裡面的介面差不多:
UITableViewDataSource
UITableViewDelegate
// // MyUiTabview.m // MyUItableView // // Created by xiaoyuan on 15/4/24. // Copyright (c) 2015年 xiaoyuan. All rights reserved. // #import "MyUiTabview.h" #import "MyCellTableViewCell.h" @interface MyUiTabview ()<UITableViewDataSource,UITableViewDelegate> { UITableView*my; UIImageView*head; UILabel*name; int TB_SECTION_COLLECT; int TB_SECTION_UPDATA; int TB_SECTION_SETTING; int TB_SECTION_QUIT; int totalSectionCount; } @property(retain,nonatomic) NSArray*titles; @property(retain,nonatomic) NSArray*pic; @end @implementation MyUiTabview @synthesize titles; @synthesize pic; - (void)viewDidLoad { [super viewDidLoad]; //加navigationController 不透明 // Do any additional setup after loading the view. self.view.backgroundColor =[UIColor whiteColor]; self.navigationController.navigationBar.barTintColor =[UIColor redColor]; [self.navigationController.navigationBar setTranslucent:NO]; UILabel *title =[[UILabel alloc] initWithFrame:CGRectZero]; title.textAlignment = NSTextAlignmentCenter; title.textColor = [UIColor whiteColor]; title.backgroundColor =[UIColor clearColor]; self.navigationItem.titleView = title;
[email protected]"個人中心"; [title sizeToFit]; [self iniview]; my = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds]; my.backgroundColor =[UIColor whiteColor]; my.separatorStyle = UITableViewCellEditingStyleNone; [self.view addSubview:my]; my.delegate = self; my.dataSource =self; [self populateTableHeader]; } //初始化資料 -(void)iniview{ totalSectionCount = 4; TB_SECTION_COLLECT = 0; TB_SECTION_UPDATA = 1; TB_SECTION_SETTING = 2; TB_SECTION_QUIT = 3; [self setTitles:@[@[@"搖一搖",@"朋友圈",@"設定"],@[@"個人中心"],@[@"微信"]]]; [self setPic:@[@[@"",@"",@""],@[@""],@[@""]]]; } //加頭 -(void)populateTableHeader { my.tableHeaderView = ({ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 120.0f)] ; head =[[UIImageView alloc]init]; head.image=[UIImage imageNamed:@"default_avatar_shadow.9.png"]; head.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; head.frame = CGRectMake(0, 10, 80, 80); head.layer.masksToBounds = YES; head.layer.cornerRadius = 40.0; head.layer.borderColor = [UIColor whiteColor].CGColor; head.layer.borderWidth = 3.0f; head.layer.rasterizationScale = [UIScreen mainScreen].scale; head.layer.shouldRasterize = YES; head.clipsToBounds = YES; [view addSubview:head]; head.userInteractionEnabled = YES; UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onUserFaceIvClick)]; [singleTap setNumberOfTapsRequired:1]; [head addGestureRecognizer:singleTap]; int ypos = 120; int screenWidth = self.view.frame.size.width - 2 * 6; UILabel * nameLb = [[UILabel alloc] initWithFrame:CGRectMake(85, 30, 200, 200)]; nameLb.text = @"逗比"; nameLb.font = [UIFont systemFontOfSize:15]; nameLb.textAlignment = NSTextAlignmentCenter; [view addSubview:nameLb]; nameLb.userInteractionEnabled = YES; singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onUserNameClick)]; [singleTap setNumberOfTapsRequired:1]; [nameLb addGestureRecognizer:singleTap]; ypos += 6 + 10; ypos += 40; CGRect frame = view.frame; frame.size.height = ypos; view.frame = frame; view; }); } //加分割線 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 520, 30)]; view.backgroundColor = [UIColor grayColor]; return view; } //分割線寬度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 12; } //每個分組有多少行 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if(TB_SECTION_COLLECT == section) { return titles.count; } else { return 1; } } //相當於getview -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @"Cell"; MyCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[MyCellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } if(indexPath.section < TB_SECTION_QUIT) { [cell populate:[[self.pic objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] title:[self.titles[indexPath.section] objectAtIndex:indexPath.row] height:44 style:MCC_STYLE_NORMAL]; if (indexPath.section == TB_SECTION_COLLECT) { UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0,44, 400, 1)]; footView.backgroundColor =[UIColor grayColor]; [cell addSubview:footView]; } } return cell; } //一共有多少行 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return totalSectionCount; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
下面是自定義的cell,這個就是item,這蘋果的算座標給我算迷糊的,都不知道哪是哪來,話說蘋果手機的螢幕是多大的啊,我都不知道,誰讓我不是富二代哪,也買不起蘋果手機,你說整個Mac咋買的啊,這個應該從85年就開始攥錢,得從這說起,那是一個非常黑,非常靜的夜晚,就說月黑風高,我翻牆闖進了李寡婦家,搶了2元錢,這為我買Mac注資了第一桶金,哎,也不知道現在李寡婦現在什麼樣了,好懷念跟隔壁老王一起玩耍的日子啊!如果我人生要是能重來,我就學文,我就當官去,貪汙,出國,然後被遣送回國,哈哈,不扯來,貼程式碼了!
</pre><pre name="code" class="objc">// MyCellTableViewCell.m // MyUItableView // // Created by xiaoyuan on 15/4/24. // Copyright (c) 2015年 xiaoyuan. All rights reserved. // #import "MyCellTableViewCell.h" @interface MyCellTableViewCell(){ } @property (retain,nonatomic) UILabel *title; @property(retain,nonatomic) UILabel *back; @end @implementation MyCellTableViewCell @synthesize title; @synthesize back; @synthesize icon; static int iconsize = 24; - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if(self){ icon =[[UIImageView alloc] initWithFrame:CGRectMake(6 , (54-iconsize)/2, iconsize, iconsize)]; [self.contentView addSubview:icon]; title =[[UILabel alloc] initWithFrame:CGRectMake(6*2+iconsize, 22, 1000,44)]; title.font =[UIFont systemFontOfSize:15]; [self.contentView addSubview:title]; } return self; } -(void)populate:(NSString *)iocn title:(NSString *)title height:(int)height style:(int)styles{ self.icon.hidden = NO; self.title.hidden = NO; CGRect frame = self.title.frame; frame.origin.y = (height-40) / 2; self.title.frame = frame; self.title.text = title; } @end
//
// MyCellTableViewCell.h
// MyUItableView
//
// Created by xiaoyuan on 15/4/24.
// Copyright (c) 2015年 xiaoyuan. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface MyCellTableViewCell : UITableViewCell
#define MCC_STYLE_NORMAL 0
#define MCC_STYLE_QUIT_BTN 100
@property(strong,nonatomic) UIImageView *icon;
//定義方法
-(void ) populate:(NSString*) iocn title:(NSString*) title height:(int) height style:(int) styles;
@end
哈哈,應該是寫完了,不說了,這麼晚了,我開始裝逼去了,扯淡結束,裝逼去了!
大神勿噴!
相關推薦
IOS學習之UiTableView仿個人中心頁面,據說學會這個控制元件就能裝逼了(二)
蘋果電腦真心不習慣啊,一邊開發使windows一邊是Mac 都不知道按鍵盤哪個鍵了。這UiTableView根android ListView一樣重要,等學會這個以後我就出去裝逼,但願裝逼不要被大神鄙視,哎,沒辦法,半路出家,誰讓我大學學的機械專業,還這麼笨的!如果人生能出
VUE DEMO 之模擬登入 個人中心頁面之間資料傳值
lalala~ 先上程式碼吧: login.html <!DOCTYPE html> <html lang="en"> <head> <meta
小程式個人中心頁面,模組入口搭建
通常我們的個人中心頁面,都具備有其他模組的入口方式。入口方式主要有以下兩種: 例如: 將小程式的跳轉頁面的連結,放入JS中的 data 資料。wxml中通過使用wx:for 實現入口模組跳轉問題。 HTML: <view class='service'&g
在visual studio 2017下用xamarin for android 做個簡單的註冊頁面,包含單選控制元件,多選控制元件和下拉選單控制元件
照著牛腩老師的視訊,自己做了個註冊頁面,實現了簡單的單選控制元件、多選控制元件、下拉選單控制元件的使用,由於日曆控制元件太醜,就不模仿了,下面就是reg.axml的佈局效果,後面是程式碼。 , <?xml version="1.0" encoding="utf-8"?
iOS開發之UITableView資料為空的提示頁面
經常用UITableView,一定會遇到資料為空的情況,這時需要在空頁面上放一個圖片和一行文字提示資料為空,下面整理了兩種方法來實現這個功能。 第一個是繼承UITableView,再新類中整合圖片和文字 #import <UIKit/UIKit.h> #imp
Snail—iOS網絡學習之得到網絡上的數據
interface rms task conn log esp self. 響應 url 在開發項目project中,尤其是手機APP,一般都是先把界面給搭建出來。然後再從網上down數據 來填充 那麽網上的數據是怎麽得來的呢,網絡上的數據無非就經常使用的兩種JSON和
ios學習之旅---指針也不難
ror 邏輯 初始化 維數 賦值運算 等價 格式 沒有 本質 1、認識指針#include <stdio.h> //基本數據類型作為函數參數傳遞是值傳遞 //void moveFront(int x ,int y) //{ // x = x + 2;
ios學習之旅--oc對象的關系
pos 其它 對象 found self 面向對象設計原則 ipa 匿名 nsstring 1.匿名對象:就是沒有名字對象 1、匿名對象僅用一次 使用場景: 1、當我們僅僅要調用一個對象的某個方法一次的時候能夠使用匿名對象 2
Linux運維學習之LAMP搭建個人博客網站
個人博客、lamp 從開始學習Linux,我就知道搭建博客,也很好奇怎麽搭建的博客,今天終於學到了這個知識點,網上的很多的教程感覺都是含糊其辭,對於基礎稍微有點薄弱的,根本實現不出來,而今天我就來篇基礎教程,基於LAMP來搭建,L:Linux,A:apache,M,mysql或mariadb,P:php
ios開發之--UITableView中的visibleCells的用法
.com format transform ati tableview bool deque property ons 先上圖: 具體代碼如下: #import "ViewController.h" @interface ViewController ()<
python學習之網站的編寫(HTML,CSS,JS)(五)----------a標籤,用於實現網頁的跳轉和頁面具體位置的跳轉
a標籤既可以實現頁面的跳轉也可以實現具體位置的跳轉,見如下程式碼: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <tit
react專案實戰五 個人中心頁面
新增庫依賴 npm install browser-cookies --save 進行瀏覽器cookie的操作 個人中心頁面 頁面的開發沒有什麼難度,直接使用antd-mobile的元件即可 src\component\usercenter\usercente
ios學習之 關於Certificate、Provisioning Profile、App ID的介紹及其之間的關係
剛接觸iOS開發的人難免會對蘋果的各種證書、配置檔案等不甚瞭解,可能你按照網上的教程一步一步的成功申請了真機除錯,但是還是對其中的緣由一知半解。這篇文章就對Certificate、Provisioning Profile等做個總結。 1.概念介紹 如果你擁有一個開發者賬戶的話,在iOS Dev Cente
iOS學習之Swift史上最全第三方輪子大全
@SwiftLanguage 更新至 2016-2-1,最近新收錄 Graph, Localize-Swift, Cuckoo, Gecco, AudioKit, vapor, Every.swift 等 7 個,合計已收錄 297 個。詳見本文件。 工具類 專案 開
iOS開發之UITableView中計時器的幾種實現方式(NSTimer、DispatchSource、CADisplayLink)
最近工作比較忙,但是還是出來更新部落格了。今天部落格中所涉及的內容並不複雜,都是一些平時常見的一些問題,通過這篇部落格算是對UITableView中使用定時器的幾種方式進行總結。本篇部落格會給出在TableView中使用NSTimer或者DispatchSourcer中常見的五種方式。當然下方第一種方式是常規
IOS學習之——向cell表格裡面填資料
向表格中增加資料 方式一 : reloadData 重新整理 tableView 方式二 : insertRowsAtIndexPath 只更新一部分 注意:沒有多執行緒是第二種方式效能低
ios 學習之 Simple Calculator Application
// // ViewController.h // ocTest // // Created by Hu Li on 2018/12/30. // Copyright © 2018 Hu Li. All rights reserved. // #import <UIKit/UIKit.h
【IOS學習之常見問題】 Program License Agreement updated
遇到問題: 因為要上架一款新的app,就需要在蘋果開發者中心(https://developer.apple.com/account/ios/certificate/)去申請釋出證書,於是登陸進去,就提示Program License Agreement up
微信小程式微商城(九):微信授權並實現個人中心頁面頁面
看效果 開發計劃 1、實現微信授權並獲取使用者資訊 2、個人中心頁面佈局 一、實現微信授權並獲取使用者資訊 mine.js onLoad: function () { if (app.globalData.userInfo) {
android 學習之Fragment+ViewPager實現頁面左右滑動標籤頁
ViewPager 結合Fragment實現一個Activity裡包含多個可滑動的標籤頁,每個標籤頁可以有獨立的佈局及響應。 如下所示。 我們可以藉助TabLayout來實現頂部導航。Activity佈局檔案如下: <?xml version="1.0" encod